{"id":19947324,"url":"https://github.com/clementvidon/pushswap","last_synced_at":"2025-07-27T00:35:54.082Z","repository":{"id":119380519,"uuid":"483279621","full_name":"clementvidon/pushswap","owner":"clementvidon","description":"Sort problem ","archived":false,"fork":false,"pushed_at":"2022-08-18T15:21:46.000Z","size":1344,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T14:18:38.644Z","etag":null,"topics":["42","42born2code","42cursus","42paris","42projects","42school","commoncore","pushswap","sorting-algorithms","sorting-algorithms-implemented"],"latest_commit_sha":null,"homepage":"https://clemedon.github.io/pushswap_42/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clementvidon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-04-19T14:24:31.000Z","updated_at":"2024-06-12T10:23:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"b28d6efa-b0bc-4648-98f8-9867d9a05dfe","html_url":"https://github.com/clementvidon/pushswap","commit_stats":null,"previous_names":["clementvidon/pushswap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clementvidon/pushswap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clementvidon%2Fpushswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clementvidon%2Fpushswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clementvidon%2Fpushswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clementvidon%2Fpushswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clementvidon","download_url":"https://codeload.github.com/clementvidon/pushswap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clementvidon%2Fpushswap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267276992,"owners_count":24063221,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["42","42born2code","42cursus","42paris","42projects","42school","commoncore","pushswap","sorting-algorithms","sorting-algorithms-implemented"],"created_at":"2024-11-13T00:35:32.245Z","updated_at":"2025-07-27T00:35:54.046Z","avatar_url":"https://github.com/clementvidon.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n#           PUSHSWAP 42\n\nThe goal of this project is to sort in ascending order numbers with as few operations as possible.\n\n\u003e cvidon@student.42.fr\u003cbr\u003e\n\u003e athirion@student.42.fr\u003cbr\u003e\n\u003e yobougre@student.42.fr\u003cbr\u003e\n\n##  Index\n\n**[Usage](#usage)**\u003cbr\u003e\n**[Step 1. Init](#Init)**\u003cbr\u003e\n**[Step 2. Pre-sort](#pre-sort)**\u003cbr\u003e\n**[Step 3. Sort](#sort)**\u003cbr\u003e\n\n##  Usage\n\nRun `make` in the root of the projet and launch as follows:\n\n    ./push_swap \u003cnumbers_to_sort\u003e\n\nExample: `./push_swap \"5 3 9 2 7\"`\n\n***Makefile rules***\n\n- `make` -- compiles philo.\n- `make clean` -- deletes object files.\n- `make fclean` -- deletes object files and philo.\n- `make re` -- `fclean` + `make``.`\n\n##  Init\n\nInput: `./push_swap \"5 3 9 2 7\"`\n    \nInit the Stack_A.\n\n    Stack_A\n    5\n    3\n    9\n    2\n    7\n\n##  Pre-sort\n\nFirst we need to find the `median` so we sort a tab of integer, we\npick its middle element as the `median`.\n\n    Tab\n    9\n    7\n    5  ← median\n    3\n    2\n\nWe push from Stack_A to Stack_B all the elements that are smaller\nthan the median (by repeating `ra` and using `pb` when required).\n\n    Stack_A             Stack_B\n    7                   2\n    9                   3\n    5\n\nWe repeat the two previous steps until there are 2 elements left in\n`Stack_A`.\n\n    Tab \n    7\n    9  ← new median\n    5\n\n    Stack_A             Stack_B \n    7                   5\n    9                   2\n                        3\n\n##      Sort\n\nNow the `pre-sort` is done. We need to find the `leader` and the\n`cost` for each element, `pa` the one that has the cheapest cost and\nrepeat this process.\n\n\u003e The `cost` is the distance to perform to put a `Stack_B` Element in the right\n\u003e location of the `Stack_A`.\n\n\u003e The `leader` is the closest value (in terms of value, not distance) between an\n\u003e Element in one Stack and an Element in the other Stack.\n\n    Stack_A             Stack_B  |cost|leader|\n    7 ← leader          5        | 1  | 7    |\n    9                   3        | 2  | 7    |\n                        2        | 2  | 7    |\n\nMove cheapest cost element to `Stack_A`.\n\n    Stack_A             Stack_B  |cost|leader|\n    5 ← leader          3        | 1  | 5    |\n    7                   2        | 2  | 5    |\n    9\n\nMove cheapest cost element to `Stack_A`.\n\n    Stack_A             Stack_B  |cost|leader|\n    3  ← leader         2        | 1  | 3    |\n    5\n    7\n    9\n\nMove cheapest cost element to `Stack_A`.\n\nSort done\n\n    Stack_A\n    2\n    3\n    5\n    7\n    9\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclementvidon%2Fpushswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclementvidon%2Fpushswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclementvidon%2Fpushswap/lists"}