-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This document contains my notes on 42 Common Core curriculum project "push_swap".
Subject instructions · References & further reading
This project is about sorting data on a stack, with a limited set of instructions, using the lowest possible number of actions. Its goal is reaching an optimized data sorting solution.
- Basic rules
Program name | push_swap |
---|---|
Turn in files | Makefile, *.h, *.c |
Makefile | NAME, all, clean, fclean, re |
Arguments | stack a: a list of integers |
- External functions allowed
Function name | Header file | Notes / Description |
---|---|---|
read |
sys/types.h sys/uio.h unistd.h |
ssize_t read(int fildes, void *buf, size_t nbyte); |
write | unistd.h | |
malloc | stdlib.h | |
free | stdlib.h | |
exit | ||
All functions of the MiniLibX | mlx.h | |
ft_printf | libft/ft_printf/ft_printf.h | and/or any equivalent coded by ourselves |
All functions of the libft library | libft/libft/libft.h | coded by ourselves (1st project of 42's Common Core curriculum) |
There are 2 stacks named a
and b
.
At the beginning:
-
stack a
contains a random amount of negative and/or positive integers, which cannot be duplicated. -
stack b
is empty.
The goal is to sort numbers in ascending order into stack a
using the following operations:
sa (swap a)
– swap the first 2 elements at the top of stack a
.
sb (swap b)
– swap the first 2 elements at the top of stack b
.
ss (swap both)
– sa
and sb
at the same time.
pa (push a)
– take the first element at the top of stack b
and put it at the top of stack a
.
pb (push b)
– take the first element at the top of stack a
and put it at the top of stack b
.
ra (rotate a)
– shift up all elements of stack a
by 1: the first element becomes the last one.
rb (rotate b)
– shift up all elements of stack b
by 1: the first element becomes the last one.
rr (rotate both)
– ra
and rb
at the same time.
rra (reverse rotate a)
– shift down all elements of stack a
by 1: the last element becomes the first one.
rrb (reverse rotate b)
– shift down all elements of stack b
by 1: the last element becomes the first one.
rrr (reverse rotate both)
: rra
and rrb
at the same time.
-
sort 100 random numbers in fewer than 700 operations (minimum validation standard)
-
sort 500 random numbers in fewer than 5500 operations (maximum validation standard)
-
Wikipedia: Stack
-
Wikipedia: Abstract data type
-
GeeksforGeeks: What is Stack Data Structure? A Complete Tutorial
-
Wikipedia: Analysis of algorithms
-
Wikipedia: Computational complexity
-
GeeksforGeeks: Sorting algorithms
-
- GitHub: Grokking Algorithms
-
Wikipedia: Greedy algorithm
-
rgiraud ← sorting approach I used as reference
-
Wikipedia: Radix sort
-
codepen.io: push_swap visualizer
-
GitHub: push_swap visualizer