ℹ️ Because Swap_push isn’t as natural
100/100 ✅
The Push_swap project is a sorting algorithm project that challenges you to efficiently sort a set of integers using two stacks and a limited set of instructions. Your goal is to write a C program named push_swap that calculates and displays the smallest set of instructions (in the Push swap language) to sort the given integers.
The project emphasizes the importance of sorting algorithms and their complexity. It serves as a practical introduction to algorithmic complexity and prepares you for discussions on these concepts during job interviews.
- The project must be written in C.
- Adhere to the Norm.
- Functions should not quit unexpectedly.
- Free allocated memory appropriately; no leaks.
- Submit a Makefile with required flags.
- Makefile rules:
$(NAME),all,clean,fclean,re. - If using
libft, include it in alibftfolder.
- Two stacks named
aandb. - Stack
acontains a random set of negative and/or positive numbers (non-duplicated). - Stack
bstarts empty. - Goal: Sort numbers in ascending order in stack
a. - Available operations:
| Code | Instruction | Action |
|---|---|---|
sa |
swap a | swaps the 2 top elements of stack a |
sb |
swap b | swaps the 2 top elements of stack b |
ss |
swap a + swap b | both sa and sb |
pa |
push a | moves the top element of stack b at the top of stack a |
pb |
push b | moves the top element of stack a at the top of stack b |
ra |
rotate a | shifts all elements of stack a from bottom to top |
rb |
rotate b | shifts all elements of stack b from bottom to top |
rr |
rotate a + rotate b | both ra and rb |
rra |
reverse rotate a | shifts all elements of stack a from top to bottom |
rrb |
reverse rotate b | shifts all elements of stack b from top to bottom |
rrr |
reverse rotate a + reverse rotate b | both rra and rrb |
- Makefile must not relink.
- Global variables are forbidden.
- Write a program named
push_swapthat takes stackaas an argument. - Display the smallest list of instructions to sort stack
a. - Instructions separated by '\n'.
- Minimize the number of operations for sorting.
- In case of errors, display "Error" on the standard error.
1. Clone the repository:
git clone https://github.com/Bruno0798/42_Push_Swap.git2. Compile the project:
make3. Run the program:
./push_swap 4 2 7 1- Follow project-specific requirements and guidelines.
- Efficiently implement sorting algorithms.
- Minimize the number of operations.
- Handle errors appropriately.
This project is licensed under the MIT License.
