https://github.com/ekkoz897/42cursus_push_swap
This project aims to sort data on a stack, with a limited set of instructions, using the lowest possible number of actions.
https://github.com/ekkoz897/42cursus_push_swap
42born2code 42cursus 42school algorithms c push-swap sorting-algorithms stacks
Last synced: 17 days ago
JSON representation
This project aims to sort data on a stack, with a limited set of instructions, using the lowest possible number of actions.
- Host: GitHub
- URL: https://github.com/ekkoz897/42cursus_push_swap
- Owner: Ekkoz897
- Created: 2023-01-24T13:29:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-21T18:08:46.000Z (over 1 year ago)
- Last Synced: 2024-11-14T22:34:57.524Z (11 months ago)
- Topics: 42born2code, 42cursus, 42school, algorithms, c, push-swap, sorting-algorithms, stacks
- Language: C
- Homepage:
- Size: 322 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 42 Push_Swap
Because swap_push isn't as natural
Given a set of integers, sort it using a predefined set of instructions using
two stacks. The instruction set is defined below. This program outputs a program
in push_swap instructions that sorts the input integers.## Instruction set
For the following instructions, if the instruction is not possible, the part of
it that can't be executed won't.| 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` |### Bonus
The bonus part is to write a program named checker, which will get as an argument the stack A formatted as a list of integers. Checker will then wait and read instructions on the standard input. Once all the instructions have been read, checker will execute them on the stack received as an argument (After giving the instructions press ctrl + d).
If after executing those instructions, stack a is actually sorted and b is empty, then
checker must display "OK" else "KO". If checker arguments are invalid it displays Error.The checker code can be found in the bonus_checker folder in this repository.