{"id":21340700,"url":"https://github.com/artainmo/push_swap","last_synced_at":"2025-03-16T02:42:47.125Z","repository":{"id":93053074,"uuid":"346836106","full_name":"artainmo/push_swap","owner":"artainmo","description":"42 school project. Algorithm project consisting of optimized data sorting with quicksort or other algorithm.","archived":false,"fork":false,"pushed_at":"2024-10-27T19:13:02.000Z","size":222,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T15:31:47.056Z","etag":null,"topics":["42school","algorithm","c","quicksort-algorithm"],"latest_commit_sha":null,"homepage":"","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/artainmo.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":"2021-03-11T21:00:04.000Z","updated_at":"2024-10-27T19:13:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"9f76012f-aa9e-43cf-9d75-11260d67161a","html_url":"https://github.com/artainmo/push_swap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fpush_swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fpush_swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fpush_swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fpush_swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artainmo","download_url":"https://codeload.github.com/artainmo/push_swap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817843,"owners_count":20352618,"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":["42school","algorithm","c","quicksort-algorithm"],"created_at":"2024-11-22T00:52:35.946Z","updated_at":"2025-03-16T02:42:47.108Z","avatar_url":"https://github.com/artainmo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# push_swap\n\n42 school [subject](https://cdn.intra.42.fr/pdf/pdf/74633/en.subject.pdf).\n\nAlgorithm project consisting of optimized data sorting with quicksort or other algorithm.\n\n## First algorithm trial (personally invented)\n\nIDEAL POSITION: Relative to following value depending on longest sorted chain.\n\n0. If all ordered -\u003e shortest path to correct place (ra || rra)\n1. Top b value can be inserted in ideal position -\u003e pa else goto ideal pos\n2. top \u003c top - 1 \n- If outside longest chain -\u003e opposite direction longest sorted chain (ra || rra)\n- If inside longest chain -\u003e direction closest longest chain exit\n- If all ordered -\u003e set ideal value for top b\n3. top \u003e top - 1\n- sa if it orders all\n- pb if following value is not ideal one\n- else rra\n\n## Second algorithm trial (personally invented)\nIDEAL POSITION: Relative to following or following value depending on longest sorted chain.\n\nEach time wanting to use ra, rra or sa check if rr or rrr or ss could be used instead to sort b at same time\n-\u003e if topb \u003c topb - 1 -\u003e ss (because b gets inserted inversely into a must ideally be inversed)\n-\u003e if b is ordered but not ideally rr or rrr until ideal position\n\n0. If all ordered -\u003e shortest path to correct place (ra || rra)\n1. Top b value can be inserted in ideal position -\u003e pa else if a ordered goto ideal pos for b\n2. If no longest chain exists -\u003e sa if ideal else pb\n3. If inside longest chain:\n* goto fastest exit of longest chain\n4. If outside longest chain \n* sa if ideal pos next to longest chain\n* else pb\n\n## Third algorithm trial (personally invented)\nIDEAL POSITION: Relative to following or following value depending on longest sorted chain.\nORDERED: All values in correct position relative to each other but not relative to stack itself\n\nEach time wanting to use rb, rrb or sb check if rr or rrr or ss could be used instead to sort b at same time\n-\u003e if a top \u003e top -1 -\u003e ss\n-\u003e if next smallest value is in direction ra and rb is used -\u003e rr\n-\u003e if next smallest value is in direction rra and rrb is used -\u003e rrr\n\n0. Check if goal is completed (goal is pb smallest value after potentially having pb second smallest values)-\u003e if it is perform operations related to resorting b\n1. If a ordered and b empty -\u003e shortest path to correct place (ra || rra)\n2. if a ordered b no empty -\u003e goto ideal pa position\n3. If sa created ordered stack -\u003e sa\n4. Fill stack b\n* If b == 0 fill it with smallest value\n* If top a is ideal for b -\u003e pb\n* If top a is second smallest value in stack a -\u003e pb\n* Else goto ideal position in a for next b\n\n## Final algorithm: quicksort \u0026 personal\nPersonal algorithm for **small stack size**:\n\n* If a is ordered ra/rra until ideally sorted.\n* If b is ordered rb/rrb until ideally sorted.\n* If s creates ideal order in a or b -\u003e sa/sb\n\nQuicksort algorithm for **larger stack size**:\n1. Makes median of upper partition (intially whole stack a == partition 0). Moves values under median to stack b. Continues doing the median algorithm until 2 values are left or values left are sorted, each time the median algorithm is reused values are pushed to a higher partition in b.\n1. B takes median upper partition and moves values above or equal to median to stack a. Continues doing this until b is empty, if two values are left it will sort them if necessary with s.\n3. A does the same thing pushing back to B who will push back to A, until A is all sorted.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartainmo%2Fpush_swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartainmo%2Fpush_swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartainmo%2Fpush_swap/lists"}