push_swap is a 42 school algorithm project where we must sort a given list of random numbers with a limited set of instructions, using the lowest possible number of actions.
First, clone this repository and cd
into it:
$ git clone https://github.com/riceset/push_swap; cd push_swap
As this project uses the libft
you will have to clone it on the root of the repository as well:
$ git clone https://github.com/riceset/libft
Compile the executable file with:
$ make
Run the program passing a list of numbers to be sorted:
$ ./push_swap 88 543 17 999 42
The program will print the operations used to sort the list:
ra
ra
pb
ra
pb
pa
pa
- push (sends the top element of a stack to the top of another stack specified)
- swap (swaps the first 2 elements of a stack)
- rotate (sends the first element of a stack to the end of the same stack)
- reverse rotate (sends the last element of a stack to the beginning of the same stack)
In my project, I implemented stacks (an abstract data structure) using a circular doubly linked list. In this model, the sentinel
is the node between the first and the last node. Also, each node within the list has a pointer point to the next and the previous node.