Skip to content

agaleksaX/push_swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push_swap

📌 Description

push_swap is a sorting algorithm project where a stack of integers must be sorted using a limited set of operations and two stacks (a and b). The goal is to minimize the number of operations.


⚙️ Features

  • Sorting using only allowed stack operations
  • Optimized for minimal moves
  • Handles different input sizes efficiently
  • Supports multiple sorting strategies
  • Bonus: checker program for validation

🛠️ Technologies

  • C
  • Algorithms
  • Data Structures (Stacks)

🚀 Compilation

make

Build bonus (checker):

make bonus

Clean files:

make clean
make fclean
make re

🚀 Usage

./push_swap 3 1 2
./push_swap "5 4 3 2 1"

Using checker (bonus):

ARG="5 3 1 4 2"
./push_swap $ARG | ./checker $ARG

📌 Example Output

pb
pb
sa
pa
pa

🧠 Algorithms

  • Small inputs (≤5) → simple sorting (hardcoded logic)
  • Medium inputs → chunk-based sorting
  • Large inputs → radix sort

The program selects the most efficient algorithm depending on input size.


🎯 Performance

  • 100 numbers → ~500–700 operations
  • 500 numbers → ~5000–7000 operations

📂 Project Structure

  • parsing – input validation
  • operations – stack operations
  • algorithms – sorting logic
  • utils – helper functions

🎯 Purpose

This project develops problem-solving skills, algorithm optimization, and understanding of low-level data structures.


🤝 Team Work

This project was developed collaboratively with a teammate. We worked together on algorithm design, debugging, and optimization strategies, improving both performance and code quality.


👤 Author

Aghvan Aleksanyan 42 Yerevan Student

About

Sorting algorithm in C using two stacks with optimized operations (push_swap project)

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages