- About the Project
- Subject Overview
- Project Requirements
- Algorithm & Data Structures
- Usage
- Installation
- Contributing
- License
Push Swap is a sorting algorithm project designed for the 42 curriculum. The main goal is to sort a stack of integers using a limited set of stack operations, optimizing for the least number of moves. This project emphasizes algorithmic thinking, data structure manipulation, and performance optimization, crucial skills in software engineering and competitive programming.
push_swap: Generates the optimal sequence of operations to sort a stack of integers, minimizing the operation count.
- Custom stack implementation
- Algorithm optimization for minimal operation count
- Error handling for invalid input, duplicates, and overflows
- Efficient memory management (no memory leaks)
- Performance-focused design
- Input: A list of integers as program arguments
- Output: A sequence of stack operations (sa, sb, pa, pb, ra, rb, rra, rrb, rr, rrr) to sort the stack
- Constraints:
- Only allowed stack operations
- No built-in sorting functions
- Must handle edge cases (duplicates, empty input, invalid characters)
- Fastest possible sorting for large data sets (up to 500 numbers)
- Evaluation Criteria:
- Correctness of sorting
- Efficiency (number of moves)
- Code quality and documentation
This project uses a custom algorithm based on the weights of moves to determine the most efficient sequence of stack operations. Every possible move is weighted and evaluated to ensure that the overall sorting process uses the minimal number of operations. The algorithm is designed specifically for this project and is highly optimized for effectiveness.
To achieve high performance and effectiveness, various data structures were used, including:
- Linked lists: Used for stack representation, allowing dynamic and efficient manipulation of elements.
- Custom-optimized structures: Tailored for fast access and modification, ensuring minimal overhead during operation calculations.
All data structures were carefully chosen and tuned to maximize speed and efficiency throughout the sorting process.
# Compile
make
# Run push_swap with a sequence of integers
./push_swap 3 2 1 6 5 8
# Output: A list of stack operations to sort the input
- Clone the repository
git clone https://github.com/artidek/42_push_swap.git cd 42_push_swap
- Build the project
make
Contributions are welcome! Please open issues or submit pull requests for bugs, enhancements, or optimizations.
This project is part of the 42 Curriculum and is provided for educational purposes only. Please do not plagiarize.
Keywords: C, sorting algorithm, stack, data structure, push_swap, optimization, performance, custom algorithm, move weights, memory management, 42 school, competitive programming, checker, input validation, code quality, software engineering