Skip to content

mahdemir/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔄 Push Swap

This project will make you sort data on a stack, with a limited set of instructions, using the lowest possible number of actions. To succeed you’ll have to manipulate various types of algorithms and choose the most appropriate solution (out of many) for an optimized data sorting.

🛠️ Compilation

The Makefile creates two programs, push_swap and checker.
Clone this repository and go in to the root of the directory by running:

git clone https://github.com/mahdemir/push_swap/ && cd push_swap

Now you can run make to create a executables named push_swap & checker

🔄 Push swap

The program sorts the stack_a and gives as output a list of all steps needed to complete the sort.

This is how to use push_swap:

./push_swap "random_numbers"
e.g:
    ./push_swap 11 38 42 1923 2
    ./push_swap "11 38 42 1923 2"

✅ Checker

Thanks to the checker program, you will be able to check whether the list of instructions generated by the push_swap program actually sorts the stack properly. The program expects to write the instruction needed in the STD_INPUT to stort the number passed in as argument by running the checker program.

This is how to use checker:

./checker "random_numbers"
e.g:
    ./checker 11 38 42 1923 2
    ./checker "11 38 42 1923 2"


More convenient way to use the program is to pass the output of push_swap to the checker directly by piping it like this:

ARG="SOME_RANDOM_NUMS"; ./push_swap $ARG | ./checker $ARG

⚙️ Algorithm logic

Pushing nodes from stack_a to stack_b, but sorting them already in desending order in stack_b so if you push them back to stack_a, they are already sorted. Genius right?

👀 Push swap in action!

push_swap

🌳 Folder structure

.
├── Makefile
├── README.md
├── img
│   ├── 100_numbers_540steps.gif
│   └── 500_numbers_5326steps.gif
├── inc
│   ├── checker.h
│   └── push_swap.h
└── src
    ├── checker
    │   ├── check_arguments_bonus.c
    │   ├── checker.c
    │   ├── checker_utils.c
    │   ├── push_bonus.c
    │   ├── rev_rotate_bonus.c
    │   ├── rotate_bonus.c
    │   └── swap_bonus.c
    └── push_swap
        ├── algorithm.c
        ├── algorithm_utils.c
        ├── check_arguments.c
        ├── error_handeling.c
        ├── init_list_a.c
        ├── init_list_b.c
        ├── init_stack.c
        ├── main.c
        ├── push.c
        ├── rev_rotate.c
        ├── rotate.c
        ├── sort_three.c
        ├── stack_utils.c
        └── swap.c

🌐 Resource

About

Because Swap_push isn’t as natural

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published