{"id":25189744,"url":"https://github.com/idriz4work/push_swap","last_synced_at":"2025-10-19T15:34:03.885Z","repository":{"id":275381144,"uuid":"925923681","full_name":"Idriz4work/push_swap","owner":"Idriz4work","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-01T21:58:20.000Z","size":1809,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T22:23:42.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Idriz4work.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-02T04:32:17.000Z","updated_at":"2025-03-01T21:58:24.000Z","dependencies_parsed_at":"2025-02-02T05:22:45.454Z","dependency_job_id":"c40e9b51-e274-4c7c-a0ea-03bc46dc7082","html_url":"https://github.com/Idriz4work/push_swap","commit_stats":null,"previous_names":["idriz4work/push_swap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idriz4work%2Fpush_swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idriz4work%2Fpush_swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idriz4work%2Fpush_swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idriz4work%2Fpush_swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Idriz4work","download_url":"https://codeload.github.com/Idriz4work/push_swap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247167113,"owners_count":20894870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-09T21:16:55.392Z","updated_at":"2025-10-19T15:34:03.767Z","avatar_url":"https://github.com/Idriz4work.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Push Swap\nA project that implements an efficient sorting algorithm using two stacks and a limited set of operations.\n\n\n\n## Overview\nPush Swap is a sorting algorithm project that challenges you to sort a stack of integers using two stacks (A and B) and a specific set of operations. The goal is to sort all numbers in stack A in ascending order while minimizing the number of operations used.\n\n## Algorithm: Osman Sort (95%)\nThe project implements the Osman sort algorithm, an efficient approach that achieves excellent performance with less than 700 operations for sorting 100 random numbers. Key features include:\n\n- **Operation-Optimal Pushing**: The algorithm intelligently pushes values from stack A to stack B by calculating and selecting moves that require the minimum number of operations\n- **Complete B-Stack Utilization**: Unlike traditional approaches, Osman sort transfers all elements to stack B before beginning the sorting process\n- **Turk Sort Inspiration**: While sharing some concepts with Turk sort, Osman sort implements distinct optimizations and decision-making processes\n- **Performance**: Consistently achieves sub-700 operation counts for 100-number sets, making it highly competitive for the Push Swap project requirements\n\n## Detailed Implementation Steps\n\n### Initialization Phase\n1. Push the first two elements from stack A to stack B to establish initial smallest and largest numbers\n2. These elements serve as reference points for subsequent comparisons\n\n## Flow Chart\n```mermaid\ngraph TD\n    A[Start] --\u003e B[Push 2 elements to Stack B]\n    B --\u003e C[Calculate costs for each number in Stack A]\n    C --\u003e D[Find number with minimum operations]\n    D --\u003e E[Execute rotations]\n    E --\u003e F[Push to Stack B]\n    F --\u003e G{Stack a empty ?}\n    G --\u003e|No| C\n    G --\u003e|Yes| H[ final sort everything is sorted in descending order]\n    H --\u003e I[Push back to Stack A]\n    I --\u003e J[End]\n```\n\n### Main Sorting Process\n1. **Cost Calculation**:\n   - For each number in stack A, calculate the total operations needed to place it in the correct position in stack B\n   - Compare each number with stack B's smallest and largest values\n   \n2. **Optimal Move Selection**:\n   - Choose the number requiring the minimum total operations\n   - Calculate required rotations for both stacks\n   - Execute simultaneous rotations when possible to optimize operation count\n\n3. **Three-Element Optimization**:\n   - Stop pushing to stack B when three elements remain in stack A\n   - Perform quick sort on these remaining elements\n\n4. **Final Organization**:\n   - Push elements back to stack A in correct order\n   - Perform final rotations to position smallest number at top\n\n## Visualizer\nThe project includes a visualizer tool to help understand the sorting process:\n- Real-time visualization of stack operations\n- Color-coded elements to track movements\n- Step-by-step execution view\n- Operation count display\n\nTo use the visualizer:\n```bash\n# Run with visualizer\n./push_swap_visualizer\n```\n\n## How it Works\nThe program takes a list of integers as input in stack A, with stack B initially empty. Using a combination of push, swap, and rotate operations, the program must sort all numbers in ascending order in stack A, with stack B empty at the end.\n\n### Available Operations\n| Operation | Description |\n|-----------|-------------|\n| `sa` | Swap first 2 elements at the top of stack A |\n| `sb` | Swap first 2 elements at the top of stack B |\n| `ss` | Execute `sa` and `sb` simultaneously |\n| `pa` | Push top element from stack B to stack A |\n| `pb` | Push top element from stack A to stack B |\n| `ra` | Rotate stack A up (first element becomes last) |\n| `rb` | Rotate stack B up (first element becomes last) |\n| `rr` | Execute `ra` and `rb` simultaneously |\n| `rra` | Reverse rotate stack A (last element becomes first) |\n| `rrb` | Reverse rotate stack B (last element becomes first) |\n| `rrr` | Execute `rra` and `rrb` simultaneously |\n\n## Checker Program\nThe checker program is a crucial component for validation:\n\n### Features\n- Reads operations from standard input\n- Validates operation syntax\n- Executes operations on the stacks\n- Verifies final sorted state\n\n### Error Handling\n- Empty strings\n- Non-numeric parameters\n- Duplicates\n- Invalid instructions\n- Memory management\n\n### Usage\n```bash\n# Run checker independently\n./checker 4 67 3 87 23\n\n# Pipe push_swap output to checker\n./push_swap 4 67 3 87 23 | ./checker 4 67 3 87 23\n```\n\n### Output\n- `OK`: Stack is properly sorted\n- `KO`: Stack is not sorted\n- `Error`: Invalid input or operations\n\n## Installation \u0026 Usage\n```bash\n# Compile both programs\nmake\n\n# Run push_swap\n./push_swap 4 67 3 87 23\n\n# Validate with checker\n./push_swap 4 67 3 87 23 | ./checker 4 67 3 87 23\n```\n\n## Visualizer\n[![Visualizer Video](https://img.youtube.com/vi/your_video_id/0.jpg)](https://www.youtube.com/watch?v=your_video_id)\n\n## Project Requirements\n- Conforms to 42 Norm\n- Uses only allowed libc functions: write, read, malloc, free, exit\n- No memory leaks\n- Comprehensive error handling\n- No unexpected terminations\n\n## Algorithm Considerations\n- Osman sort actively calculates operation costs for each potential move\n- Different approaches may be needed for different input sizes\n- Optimization is crucial for performance benchmarks\n- Numbers can be normalized/indexed to simplify the sorting process\n\n## License\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidriz4work%2Fpush_swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidriz4work%2Fpush_swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidriz4work%2Fpush_swap/lists"}