This project was completed as part of the curriculum at School 42. The goal of the project is to sort a stack of integers using a limited set of operations.
To install and run the program, follow these steps:
- Clone the repository to your local machine.
- Open a terminal window and navigate to the root directory of the project.
- Run the command
make
to compile the program. - Run the program using the command
./push_swap [list_of_numbers]
.
The program takes a list of integers as a command-line argument and sorts them using the following operations:
sa
: swap the first two elements of stack A.sb
: swap the first two elements of stack B.ss
: dosa
andsb
simultaneously.pa
: push the first element of stack B onto stack A.pb
: push the first element of stack A onto stack B.ra
: rotate stack A so that the first element becomes the last.rb
: rotate stack B so that the first element becomes the last.rr
: dora
andrb
simultaneously.rra
: reverse rotate stack A so that the last element becomes the first.rrb
: reverse rotate stack B so that the last element becomes the first.rrr
: dorra
andrrb
simultaneously.
The program must output a list of operations that sorts the stack in ascending order using the smallest number of operations possible.
Here's an example of how to use the program to sort a stack of numbers:
$ ./push_swap 3 1 4 2
sa
ra
sa
rra
In this example, the program sorts the stack [3, 1, 4, 2]
using the operations sa
, ra
, sa
, and rra
.
This project was completed by Edgar Boutillot as part of the curriculum at School 42.