Skip to content

My push_swap project for the 42 Cursus. An integer sorting program, using a limited set of instructions. 84/100

Notifications You must be signed in to change notification settings

lachlanstephen/push_swap_42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 

Repository files navigation

push_swap

Mark: 84/100

push_swap, the only mandatory project of ring 2, involved sorting data on a stack, using a limited set of instructions, in the smallest amount of moves possible. This project acted as an introduction to various sorting algorithms, and the concept of time and space complexity, with the idea to have the most optimised data sorting algorithm based on the restrictions.

I opted to go down the path of bit comparisons, which is also known as a radix sort. I chose this algorithm as I enjoyed the logic behind the solution, and the mathematical approach. Having used bitwise operators in minitalk, and then worked with complex numbers in fract-ol, I liked the idea of going down the more mathematical route and working with the numbers in bit form.

Running the program

To compile and run the program, run the following commands:

# Make using the Makefile

make	# Creates the push_swap executable

# Run the executable, using the following arguments

./push_swap <int_list>

# e.g. ./push_swap 1 6 2 4 3

Note: The list of integers given must be an unsorted list of unique integers.

Important

Use the included checker programs (provided by 42) to make sure the integers are correctly sorted.

Tip

To generate a random int list, I used calculator soup's number generator and set it to a variable for later use.

# Set integer list to variable

ARG="<copied_list_of_ints>"

# e.g. ARG="1 5 2 ... 9 6 3"

# Run program using variable

./push_swap $ARG

Caution

Setting a variable doesn't seem to work on ZSH, so must use bash.

Checking results

To check the integer list is successfully sorted:

./push_swap $ARG | ./checker_programs/<checker_OS> $ARG

Note: <checker_OS> must be changed with the version that works for your OS

Important

To check how many moves it takes to sort, pipe the command wc -l, as we print one line per instruction

./push_swap $ARG | wc -l

Plans for repository

  • Implement optimisations for the sorting algorithm I currently use
  • Attempt to use different sorting algorithms to achieve greater optimisation
  • Distant Futute: Attempt bonus - build own checker/visualiser

Releases

No releases published

Packages

No packages published