https://github.com/msabr/push_swap_1337
A sorting algorithm project that involves sorting a stack of numbers with a limited set of operations, using two stacks (a and b). It focuses on algorithmic efficiency and optimization. 🚀
https://github.com/msabr/push_swap_1337
1337cursus 1337school 42cursus 42projects 42school makefile open-source pushswap pushswap-42 sorting sorting-algorithms stack
Last synced: 6 months ago
JSON representation
A sorting algorithm project that involves sorting a stack of numbers with a limited set of operations, using two stacks (a and b). It focuses on algorithmic efficiency and optimization. 🚀
- Host: GitHub
- URL: https://github.com/msabr/push_swap_1337
- Owner: msabr
- Created: 2025-03-12T01:59:06.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-03-12T02:21:44.000Z (7 months ago)
- Last Synced: 2025-03-12T03:18:40.413Z (7 months ago)
- Topics: 1337cursus, 1337school, 42cursus, 42projects, 42school, makefile, open-source, pushswap, pushswap-42, sorting, sorting-algorithms, stack
- Language: C
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# **Libft - 42 Network**
## **Overview**
This project is the first step in my journey at **42 Network**. The goal of **Libft** is to rebuild essential functions from the C standard library, along with additional utility functions that will be useful throughout the entire curriculum. By implementing these functions, I gain a deeper understanding of low-level programming, memory management, and algorithmic problem-solving.## **Project Scope**
Libft consists of multiple categories of functions, including:- **Libc Functions**: Rewriting standard library functions such as `strlen`, `strcpy`, `strcmp`, `memset`, `bzero`, and more.
- **Memory Management**: Implementing functions like `malloc`, `free`, and `realloc` to handle dynamic memory allocation.
- **String Manipulation**: Functions for handling and modifying strings efficiently.
- **Linked Lists**: Implementing basic linked list structures and operations.
- **Custom Utility Functions**: Additional helper functions that facilitate various tasks in future projects.### Key Features
- Sorts a stack using these operations:
- `sa`: swap the top two elements of stack A.
- `sb`: swap the top two elements of stack B.
- `ss`: perform `sa` and `sb` simultaneously.
- `pa`: push the top element of stack B to stack A.
- `pb`: push the top element of stack A to stack B.
- `ra`: rotate stack A upward (top element goes to bottom).
- `rb`: rotate stack B upward.
- `rr`: perform `ra` and `rb` simultaneously.
- `rra`: reverse rotate stack A (bottom element goes to top).
- `rrb`: reverse rotate stack B.
- `rrr`: perform `rra` and `rrb` simultaneously.
- Optimizes for minimal instructions (e.g., ≤ 12 moves for 5 numbers, ≤ 700 for 100).
- Handles invalid inputs with an "Error" message.
- Bonus: validates sorting with a separate checker tool that processes custom instruction sequences.### Restrictions
- Written in C, compliant with the 42 Norm.
- No unexpected crashes (e.g., segmentation faults).
- No memory leaks from heap allocations.
- Compiled with `-Wall -Wextra -Werror`.
- Limited to specified stack operations; no direct array sorting allowed.## Getting Started
### Prerequisites
- C compiler (e.g., `clang`).
- `make` utility.
- `libft` library in the `Libft` directory.### How to Build and Run
1. Clone the repository:
```bash
git clone https://github.com/msabr/PUSH_SWAP_1337
cd PUSH_SWAP_13372. Build the mandatory part:
```bash
make3. Run `push_swap` with a list of integers:
```bash
./push_swap#### Additional commands
- `make clean`: remove object files.
- `make fclean`: remove the program and object files.
- `make re`: rebuild everything.## Project Structure
- `push_swap.h`: header for mandatory part.
- `functions_*.c`: source files for push_swap (e.g., main.c, sort.c, push.c).
- `Makefile`: compilation automation.
- `Libft/`: directory for the libft library.