In this repository, you can accsess the code created for the Push Swap project, mandatory and bonus part.
Keywords | Skills |
---|---|
- Sorting algorithms | - Rigor |
- Battery concept and handling elements | - Unix |
- Algorithm implementation | - Algorithms & AI |
- Imperative programming |
This project involves creating a program to sort a list of numbers in ascending order using a set of predefined movements. The sorting process utilizes two stacks, Stack A and Stack B:
- Stack A: Initially holds the list of numbers that need to be sorted.
- Stack B: Starts empty and is used as an auxiliary stack during the sorting process.
The objective is to transfer the numbers from Stack A to Stack B using the defined operations to achieve a sorted sequence in ascending order.
The challenge lies in performing this sorting efficiently while adhering to the constraints and movement rules provided.
Movement | How it works |
---|---|
pa | Take the first element at the top of B and put it at the top of A. Do nothing if B is empty. |
pb | Take the first element at the top of A and put it at the top of B. Do nothing if A is empty. |
sa | Swap the first 2 elements at the top of stack A. Do nothing if there is only one or no elements. |
sb | Swap the first 2 elements at the top of stack B. Do nothing if there is only one or no elements. |
ss | sa and sb at the same time. |
ra | Shift up all elements of stack A by 1. The first element becomes the last one. |
rb | Shift up all elements of stack B by 1. The first element becomes the last one. |
rr | ra and rb at the same time. |
rra | Shift down all elements of stack A by 1. The last element becomes the first one. |
rrb | Shift down all elements of stack B by 1. The last element becomes the first one. |
rrr | rra and rrb at the same time. |
Run it with:
$> ./push_swap <random_numbers>
It must display the list of instructions used to sort the list of numbers.
Clone this repository in you local computer using a terminal:
$> git clone git@github.com:GustaDNS/Push_swap.git
After cloning the project to your local repository, you can use the following commands from the Makefile:
- make all: or just make compiles the project
- make clean: deletes the object files created during compilation
- make fclean: executes the clean command and also deletes the binary files
- make re: runs the fclean command followed by make all to recompile the project
- make visualizer: runs the visualizer to use a interface and see how the algorithm work