Skip to content

ayeshamk23/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ push_swap

A stack-based sorting project using a quicksort-inspired algorithm.

πŸ“Œ Description

push_swap is a 42 School project that sorts a stack of integers using a limited set of operations and two stacks: A and B. The goal is to sort stack A with the fewest possible instructions using only push, swap, rotate, and reverse operations.

This implementation is powered by the quicksort algorithm, adapted to work within the push_swap constraints. It emphasizes algorithmic efficiency, memory control, and operation optimization.

βš™οΈ Allowed Instructions

  • sa, sb, ss β€” swap the top elements
  • pa, pb β€” push from one stack to the other
  • ra, rb, rr β€” rotate stack up
  • rra, rrb, rrr β€” reverse rotate stack down

πŸš€ How It Works

The algorithm works by recursively dividing the stack into chunks, selecting pivots, and using quicksort-style partitioning while relying on the allowed instructions to move elements between stacks.

πŸ§ͺ Example

./push_swap 4 2 5 3 1
# Output:
pb
pb
sa
pa
pa
ra
ra

About

push_swap is an algorithmic sorting project from 42 School. It sorts integers using two stacks and a limited set of operations. This version implements the sorting logic using the quicksort strategy, optimizing for minimal operation count.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors