Skip to content

This project's sorts data in a stack using a limited set of instructions, aiming to achieve the lowest possible number of actions

License

Notifications You must be signed in to change notification settings

Maroua-netizen/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Push Swap

The goal of the Push Swap project is to sort a list of integers using two stacks and a limited set of operations. The challenge is to achieve the sorting with the minimum number of moves.

Visualization

Sorting.500.numbers.in.4992.moves.mov

Features

  • Sort 100 numbers in less than 700 moves
  • Sort 500 numbers in less than 5500 moves

Instructions

  1. Clone the repository:

    git clone https://github.com/Maroua-netizen/push_swap.git
    cd push_swap
    
  2. Compile the program:

    make
  3. Run the program:

    ./push_swap <list_of_integers>

Usage Example

./push_swap 3 2 5 1 4

Operations

The following operations are used to sort the numbers:

sa : swap the first two elements at the top of stack a
sb : swap the first two elements at the top of stack b
pa : push the top element of stack b onto stack a
pb : push the top element of stack a onto stack b
ra : rotate stack a (shift all elements up by one, the first element becomes the last one)
rb : rotate stack b
rra : reverse rotate stack a (shift all elements down by one, the last element becomes the first one)
rrb : reverse rotate stack b

License

This project is licensed under the MIT License - see the LICENSE file for details.