Skip to content

push_swap 42 school project to sort random numbers using a limited set of instructions, aiming to minimize the total number of operations.

Notifications You must be signed in to change notification settings

salrowwa/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

push_swap

Efficient two-stack integer sorting using the Turk Algorithm (C, 100–500 elements, with checker bonus).


Overview

push_swap is a 42 school project designed to sort integers with minimal stack operations.
This implementation uses the Turk Algorithm, optimized for medium to large inputs, supporting both positive and negative numbers.


Algorithm

  • Moves elements between Stack A and Stack B based on a cost evaluation
  • Small subsets are sorted using a simplified deterministic method
  • Fully deterministic: same input → same output

Features

  • Two-stack sorting (Stack A & B)
  • Optimized for 100–500 integers
  • Full input validation and error handling
  • Bonus: checker program for verification
  • Strict memory management and C standard compliance

Usage

# Compile the project
make

# Generate 500 random numbers
ARG=$(seq -1000 1000 | shuf -n 500 | tr '\n' ' ')

# Run push_swap and count moves
./push_swap $ARG | wc -l

# Run push_swap with checker
./push_swap $ARG | ./checker $ARG

About

push_swap 42 school project to sort random numbers using a limited set of instructions, aiming to minimize the total number of operations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published