Skip to content

hu8813/push_swap

Repository files navigation

Push_swap using Radix sort

Push_swap is a project that involves sorting a list of integers using a limited set of operations. The goal is to sort the list with the fewest possible number of operations.

overflow handling

Do not forget to check for error handling & leaks if a number is bigger/smaller than max/min long int or long long int (overflow) !

For testing error handling and finding memory leaks, use my tester here:

Link to the tester's repository: (https://github.com/hu8813/tester_push_swap)

Sorting results and points

Input Size Average Operations Maximum Operations allowed Points Visualize
3 1-2 3
5 5-10 12
100 855-857 <1300 4/5 link
500 5739-5741 <10000 4/5

Usage

To use the push_swap program, compile it with the make command and then run it with the list of integers to be sorted as arguments. i.e.:

./push_swap 3 1 2

To test with some random numbers:

make test (will test with 10 numbers as default)

to test with n random numbers:

make test size=n i.e. make test size=5

This will output if the program passes the test, amount of operations necessary to sort, if there are any memory leaks.

Optionally, you can use the checker program to verify that the list is correctly sorted after the operations are applied. To do this, run the checker program with the list of integers and the list of operations as arguments.

Test and see how many points you can get

run: perl push_swap_tester.pl size_of_stack how_many_tests

i.e. perl push_swap_tester.pl 100 10

will run 10 different tests with 100 different numbers each time and show you how many points you can get during evaluation

Link to the repository: (https://github.com/lorenuars19/push_swap_tester)

Visualize the results

Run bash visualizer.sh to get an online link that shows the visualization.

Edit the NBR_COUNT variable in visualizer.sh file to change the numbers to sort, i.e. NBR_COUNT=100 to sort 100 numbers and visualize it

GitHub Page of this Visualizer: https://github.com/Bluegales/push-swap-pain

OR

There is another, a better visualizer in python, but this needs tkinter library, which can not be installed on school pc as it needs root.

If you want to test on private pc, you can install the push-swap-gui python program from https://pypi.org/project/push-swap-gui/. This program allows you to see the sorting process of the Push_swap project in a graphical interface, making it easier to understand how the algorithms work. Simply follow the instructions on the website to install and run the program. If you get tkinter error, means you need to install tkinter via sudo apt install python3-tk

Resources

Useful resources for understanding and implementing sorting algorithms for the Push_swap project: