Go to file
2023-10-26 19:09:02 +02:00
getnextline updated headers 2023-10-26 19:09:02 +02:00
libft updated headers 2023-10-26 19:09:02 +02:00
printf updated headers 2023-10-26 19:09:02 +02:00
src updated headers 2023-10-26 19:09:02 +02:00
tests makefilefix 2023-03-01 23:56:55 +01:00
visualizer bla 2023-03-24 16:19:05 +01:00
.gitignore update 2023-03-01 17:59:14 +01:00
LICENSE License 2023-03-01 04:38:42 +01:00
Makefile updated headers 2023-10-26 19:09:02 +02:00
push_swap.h updated headers 2023-10-26 19:09:02 +02:00
Readme.md readmeupdate 2023-03-11 08:15:52 +01:00
test.sh tester 2023-03-09 20:18:29 +01:00

Push Swap

Push Swap is a 2 stack sorting algoritm, The goal is to sort the input in as few moves as possible
I wrote my own algoritm which is a combination of quick sort and bubble sort as radix is very bad with only 2 stacks
The following is a list of the moves we are allowed to make

Move Description
pa Pushes the top number from stack B to stack A
pb Pushes the top number from stack A to stack B
sa Swaps the top 2 numbers in stack A
sb Swaps the top 2 numbers in stack B
ss Swaps the top 2 numbers in stack A and in Stack B
ra Rotates Stack A moves all items forward so the last item becomes the first
rb Rotates Stack B moves all items forward so the last item becomes the first
rr Rotates Both stacks moves all items forward, so the last item becomes the first
rra Reverse Rotates Stack A moves all items backwards, so the first item becomes the last
rrb Reverse Rotates Stack B moves all items backwards, so the first item becomes the last
rrr Reverse Rotates Both stacks moves all items backwards, so the first item becomes the last

Improvements

Improve 5 numbers algoritm

simply hardcode all possibilities with 5 numbers or less

Improve more than 30 algoritm

Gotta figure this out to always stay under the goals


Usage

Sorter

  1. Simply clone or download the repository
  2. Run make in the cloned directory
  3. Start the program with ./push_swap [numbers seperated by space]
  4. It will return the list of moves to sort the stack

Checker

  1. Simply clone or download the repository
  2. Run make bonus in the cloned directory
  3. Start the program with ./checker [numbers seperated by space]
  4. You will have to input moves seperated by a return and when you are done press CTRL + D
  5. It will return a OK or a KO.

Both

  1. You can also run both programs with ./push_swap [numbers] | ./checker [same numbers]

Tester

Todo

  • test "-" as argument
  • check for -Wall -Werror -Wextra

Usage

  1. Download test.sh to your push swap directory
  2. Make the file executable chmod +x test.sh
  3. Run ./test.sh to start the test

This project is part of the studies at 42