Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by smoustaj.


description

the goal of push_swap is to sort a list of unique numbers using the smallest possible number of steps.

we only have two tools (stacks):

  1. stack A: starts with the unsorted numbers.
  2. stack B: starts empty and is used as temporary storage.

solution overview

this program uses the RADIX Sort algorithm with a least significant bit (LSB) strategy. Instead of sorting the large original numbers, we first assign each number a simple rank (index). The program then sorts the stack by looking at the binary digits (bits) of these ranks, moving elements back and forth between Stack A and Stack B until Stack A is perfectly sorted.


instructions

compilation

Use the provided Makefile to compile the executable:

make
example :
# option 1: multiple arguments
./push_swap 10 2 1 3 4

# option 2: quoted string
./push_swap "10 2 1 3 4"

usage with the checker:
./push_swap 5 4 3 2 1 | ./checker 5 4 3 2 1
# expected output on success: OK

resources

didn't use any.

About

push_swap is an algorithmic project that focuses on sorting data using constrained operations. The goal is to sort a list of integers using two stacks (A and B) and a limited set of allowed instructions, while minimizing the total number of operations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages