{"id":20055234,"url":"https://github.com/khammerschmidt/42cursus-push_swap","last_synced_at":"2026-05-13T00:06:24.691Z","repository":{"id":227720829,"uuid":"429518241","full_name":"KHammerschmidt/42cursus-push_swap","owner":"KHammerschmidt","description":"Writing a sorting algorithm to sort a stack of integers with the least amount of instructions","archived":false,"fork":false,"pushed_at":"2022-12-11T19:39:15.000Z","size":255,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T21:33:00.783Z","etag":null,"topics":["algorithms","bitwise-operators","linked-list","radix-sort-algorithm","sorting-algorithms","visualisation"],"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/KHammerschmidt.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}},"created_at":"2021-11-18T17:21:43.000Z","updated_at":"2022-12-11T01:20:39.000Z","dependencies_parsed_at":"2024-03-14T21:14:03.501Z","dependency_job_id":null,"html_url":"https://github.com/KHammerschmidt/42cursus-push_swap","commit_stats":null,"previous_names":["khammerschmidt/42cursus-push_swap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KHammerschmidt%2F42cursus-push_swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KHammerschmidt%2F42cursus-push_swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KHammerschmidt%2F42cursus-push_swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KHammerschmidt%2F42cursus-push_swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KHammerschmidt","download_url":"https://codeload.github.com/KHammerschmidt/42cursus-push_swap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241483562,"owners_count":19970100,"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":["algorithms","bitwise-operators","linked-list","radix-sort-algorithm","sorting-algorithms","visualisation"],"created_at":"2024-11-13T12:46:58.367Z","updated_at":"2026-05-13T00:06:17.653Z","avatar_url":"https://github.com/KHammerschmidt.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg  width=\"90\" src=\"https://user-images.githubusercontent.com/19689770/129336866-169b0dc7-ea41-47d4-b50a-d466508031af.png\"\u003e\n  \n\t🧰 push_swap\n \u003c/img\u003e\n\n\u003c/h1\u003e\n\u003c/br\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003cb\u003e Algorithmic project - sorting data on a stack with limited set of instructions \u003c/b\u003e\u003c/br\u003e\n\tStart date: 09/november/2021 \u003c/br\u003e\n\t\u003csub\u003e Project status: completed 88/100 points \u003c/sub\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg alt=\"Github repo size\" src=\"https://img.shields.io/github/repo-size/KHammerschmidt/42cursus-push_swap?color=dark%20dark%20green\"/\u003e\n\t\u003cimg alt=\"Number of lines in code\" src=\"https://img.shields.io/tokei/lines/github/KHammerschmidt/42cursus-push_swap\"/\u003e\n\t\u003cimg alt=\"Languages used in repo\" src=\"https://img.shields.io/github/languages/count/KHammerschmidt/42cursus-push_swap?color=purple\"/\u003e\n\t\u003cimg alt=\"Top used progamming language\" src=\"https://img.shields.io/github/languages/top/KHammerschmidt/42cursus-push_swap?color=white\"/\u003e\t\n\u003c/p\u003e\n\n\n## 💡 About the project\n\u003e The task is to write a sorting algorithm that sorts the integers on a stack received as arguments. Sorting should not happen in the most time-efficient way, but with the smallest list of instructions as possible. The program should output the list of instructions on the STDOUT separated by '\\n' when sorting the potential different-sized stack. During the evaluation the number of operations will be compared against a limit, the maximum number of operations tolerated, e.g. maximum of 2 instructions to sort 3 random numbers and maximum 12 instructions when sorting 5 randon numbers. When finished, the smallest number should be at the top of stack a. \n\u003c/br\u003e\n\n**Scenario** \u003c/br\u003e\nThere are 2 stacks: a contains a random amount of negative and/or positive numbers without any duplicates, stack b is empty. The task is to sort stack a in ascending order numbers with a series the following operations: swap or push elements from one stack to another, as well as rotate and reverse rotate a stack. \u003c/br\u003e\n\u003c/br\u003e\n\n**Key learning points**\n  - Bit shifting operation\n  - basic algorithms\n  - handling linked lists\n  - using visualisers to see performance of program\n\u003c/br\u003e\n\n\n###  :octocat: Sorting operations overview\nThe following operations were allowed when sorting the stack:\n|     Operation    |   What is does                                                |\n|------------------|---------------------------------------------------------------|\n|[`sa`]            | swap first two elements of stack a                            |\n|[`sb`]            | swap first two elements of stack b                            |\n|[`ss`]            | perform sa and sb simultaneously                              | \n|[`pa`]            | push first element of a to top of stack b                     |\n|[`pb`]            | push first element of b to top of stack a                     |\n|[`ra`]            | shifts up all elements on stack a by 1.                       |\n|[`rb`]            | shift up all elements on stack b by 1.                        |\n|[`rr`]            | performs ra and rb simultaneously                             |\n|[`rra`]           | reverse rotate stack a (shift down by 1)                      |\n|[`rrb`]           | reverse rotate stack b (shift down by 1)                      |\n|[`rrr`]           | performs rra and rrb simultaneously                           |\n\u003c/br\u003e\n\n\n\n\n##  🌐 Radix Sort\nThe sorting algorithm applied to this project is radix sort, which is the process of sorting numbers on the stack by their bits rather than their true values. These operations are called bitwise operations and operate through bit manipulation.\nWhile there are more efficient sorting algorithms that would have needed less instructions, Radix sort required to get familiar with bitwise shifting and performed decently enough to pass the project.\nThe bitwise operators used include ```\u003e\u003e```, ```\u0026``` and ```\u003e\u003e=```. \u003c/br\u003e\n\u003c/br\u003e\n\n\n#### * ```Bitwise AND \u0026 operator```\nIt performs logical conjunction of the bits in each position of a number in its binary form, this means when comparing \ntwo values it returns 1 if both elements in the comparison are 1 otherwise 0.\n\nExamples: \n```\n0 \u0026 0 = 0\n0 \u0026 1 = 0\n1 \u0026 0 = 0\n1 \u0026 1 = 1\n```\n\n```\n  11001000\n\u0026 10111000\n__________\n= 10001000\n```\n\u003c/br\u003e\n\n#### * ```Right shift \u003e\u003e operator```\nRight-shifts a number to the right by a certain amount of bytes. It requires two operands, e.g. ``` 350 \u003e\u003e 2 ```, which will shift the bits of the number 350 by 2 places to the right.  \nUndefined behaviour arises with negative numbers or numbers that are \u003e= to the total number of bits. This is why all numbers from a stack were first assigned an index ranging from 0 - number of integers on stack by which they are sorted by.\nThe bits are being shifted to the right and empty spaces on the left side are filled with zeroes. \nThe program push_swap will then compare the rightmost value and pushes only those number to the other stack\nthat when compared with bitwise \u0026 result in 1.\n\nExample:\n```\nint temp = 114 \noperation: temp \u003e 1    \n\ntemp before operation: 01110010 \ntemp after operation:  00111001\n```\n\u003c/br\u003e\n\n#### * ```Bitwise assignment operators \u003e\u003e=```\nPerforms binary operation by the value of right operand on left operand and stores the result in the left operand.\n\nExample:\n```\n  save \u003e\u003e= 1\n```\n\u003c/br\u003e\n\n\n## 🛠️ **Usage**\n\nclone the repository:\n```bash\ngit clone https://github.com/KHammerschmidt/42cursus-push_swap \u0026\u0026\ncd 42cursus-push_swap\n```\n\nto compile the project:\n```bash\nmake\n```\n\nto launch the program with a set of numbers:\n```bash\n$ ./push_swap \"3 4 -200 13 55\"\n```\n\n\u003c/br\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhammerschmidt%2F42cursus-push_swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhammerschmidt%2F42cursus-push_swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhammerschmidt%2F42cursus-push_swap/lists"}