{"id":21700478,"url":"https://github.com/tafara-n/sorting_algorithms","last_synced_at":"2025-04-12T13:34:35.028Z","repository":{"id":218418181,"uuid":"745030865","full_name":"Tafara-N/sorting_algorithms","owner":"Tafara-N","description":"Introduction to Sorting Algorithms/Big O with C.","archived":false,"fork":false,"pushed_at":"2024-11-03T07:29:44.000Z","size":380,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T08:08:31.370Z","etag":null,"topics":["bitonic-sort","bubble-sort","cocktail-sort-list","counting-sort","heap-sort","insertion-sort-list","merge-sort","quick-sort-hoare","radix-sort","selection-sort","shell-sort"],"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/Tafara-N.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":"2024-01-18T14:02:22.000Z","updated_at":"2025-02-17T20:56:15.000Z","dependencies_parsed_at":"2024-02-04T21:43:10.836Z","dependency_job_id":"b34e1f8b-1ab4-46fa-9871-24db0e6f1896","html_url":"https://github.com/Tafara-N/sorting_algorithms","commit_stats":null,"previous_names":["tafara-n/sorting_algorithms"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Fsorting_algorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Fsorting_algorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Fsorting_algorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tafara-N%2Fsorting_algorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tafara-N","download_url":"https://codeload.github.com/Tafara-N/sorting_algorithms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248573606,"owners_count":21126868,"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":["bitonic-sort","bubble-sort","cocktail-sort-list","counting-sort","heap-sort","insertion-sort-list","merge-sort","quick-sort-hoare","radix-sort","selection-sort","shell-sort"],"created_at":"2024-11-25T20:14:26.421Z","updated_at":"2025-04-12T13:34:34.985Z","avatar_url":"https://github.com/Tafara-N.png","language":"C","readme":"![ALGORITHMS](images/willy-wonka.png)\n\n# Background Context\nThis project is meant to be done by groups of two students. Each group of two should [pair program](https://en.wikipedia.org/wiki/Pair_programming) for at least the mandatory part.\n\n## Resources\n\n## Read or watch:\n- [Sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm)\n- [Big O notation](https://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation)\n- [Sorting algorithms animations](https://www.toptal.com/developers/sorting-algorithms)\n- [15 sorting algorithms in 6 minutes](https://www.youtube.com/watch?v=kPRA0W1kECg) (**WARNING**: *The following video can trigger seizure/epilepsy. It is not required for the project, as it is only a funny visualization of different sorting algorithms*)\n- [CS50 Algorithms explanation in detail by David Malan](https://www.youtube.com/watch?v=yb0PY3LX2x8\u0026t=2s)\n- [All about sorting algorithms](https://www.geeksforgeeks.org/sorting-algorithms/)\n\n# Learning Objectives\nAt the end of this project, you are expected to be able to [explain to anyone](https://fs.blog/feynman-learning-technique/), **without the help of Google:**\n\n## General\n- At least four different sorting algorithms\n- What is the Big O notation, and how to evaluate the time complexity of an algorithm\n- How to select the best sorting algorithm for a given input\n- What is a stable sorting algorithm\n\n# Requirements\n\n## General\n- Allowed editors: `vi`, `vim`, `emacs`\n- All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -Werror -Wextra -pedantic -std=gnu89\n- All your files should end with a new line\n- A `README.md` file, at the root of the folder of the project, is mandatory\n- Your code should use the `Betty` style. It will be checked using [betty-style.pl](https://github.com/alx-tools/Betty/blob/master/betty-style.pl) and [betty-doc.pl](https://github.com/alx-tools/Betty/blob/master/betty-doc.pl)\n- You are not allowed to use global variables\n- No more than 5 functions per file\n- Unless specified otherwise, you are not allowed to use the standard library. Any use of functions like *`printf`*, *`puts`*, *`…`* is totally forbidden.\n- In the following examples, the `main.c` files are shown as examples. You can use them to test your functions, but you don’t have to push them to your repo (if you do we won’t take them into account). We will use our own `main.c` files at compilation. Our `main.c` files might be different from the one shown in the examples\n- The prototypes of all your functions should be included in your header file called `sort.h`\n- Don’t forget to push your header file\n- All your header files should be include guarded\n- A list/array does not need to be sorted if its size is less than 2.\n\n# More Info\nData Structure and Functions\n\n- For this project you are given the following `print_array`, and `print_list` functions:\n\n```c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n\n/**\n * print_array - Prints an array of integers\n *\n * @array: The array to be printed\n * @size: Number of elements in @array\n */\nvoid print_array(const int *array, size_t size)\n{\n    size_t i;\n\n    i = 0;\n    while (array \u0026\u0026 i \u003c size)\n    {\n        if (i \u003e 0)\n            printf(\", \");\n        printf(\"%d\", array[i]);\n        ++i;\n    }\n    printf(\"\\n\");\n}\n```\n\n```c\n#include \u003cstdio.h\u003e\n#include \"sort.h\"\n\n/**\n * print_list - Prints a list of integers\n *\n * @list: The list to be printed\n */\nvoid print_list(const listint_t *list)\n{\n    int i;\n\n    i = 0;\n    while (list)\n    {\n        if (i \u003e 0)\n            printf(\", \");\n        printf(\"%d\", list-\u003en);\n        ++i;\n        list = list-\u003enext;\n    }\n    printf(\"\\n\");\n}\n```\n\n- Our files `print_array.c` and `print_list.c` (containing the `print_array` and `print_list` functions) will be compiled with your functions during the correction.\n- Please declare the prototype of the functions `print_array` and `print_list` in your `sort.h` header file\n- Please use the following data structure for doubly linked list:\n\n```c\n/**\n * struct listint_s - Doubly linked list node\n *\n * @n: Integer stored in the node\n * @prev: Pointer to the previous element of the list\n * @next: Pointer to the next element of the list\n */\ntypedef struct listint_s\n{\n    const int n;\n    struct listint_s *prev;\n    struct listint_s *next;\n} listint_t;\n```\n\nPlease, note this format is used for Quiz and Task questions.\n- `O(1)`\n- `O(n)`\n- `O(n!)`\n- n square -\u003e `O(n^2)`\n- log(n) -\u003e `O(log(n))`\n- n * log(n) -\u003e `O(nlog(n))`\n- n + k -\u003e `O(n+k)`\n- …\n\nPlease use the “short” notation (don’t use constants). Example: `O(nk)` or `O(wn)` should be written `O(n)`. If an answer is required within a file, all your answers files must have a newline at the end.\n\n## Tests\nHere is a quick tip to help you test your sorting algorithms with big sets of random integers: [Random.org](https://www.random.org/integer-sets/)\n\n## Quiz questions\n\n### Question #0\n\nWhat is the time complexity of the “push” operation onto a stack?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #1\n\nWhat is the time complexity of worst case deletion from a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #2\n\nWhat is the time complexity of removing the nth element of a singly linked list? (Assuming you have a pointer to the node to remove)\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #3\n\nAssuming you have a pointer to the node to remove, what is the time complexity of removing the nth element of a doubly linked list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #4\n\nWhat is the time complexity of searching for an element in a stack of size n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #5\n\nWhat is the time complexity of “pushing” an element into a queue if you are given a pointer to both the head and the tail of the queue?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #6\n\nWhat is the time complexity of inserting at index n on an unsorted array?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #7\n\nWhat is the time complexity of inserting into an unsorted Python 3 list at index n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #8\n\nAssuming you have a pointer to the node to insert, what is the time complexity of inserting after the nth element of a doubly linked list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #9\n\nWhat is the time complexity of searching for an element in a singly linked list of size n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #10\n\nWhat is the time complexity of accessing the nth element on an unsorted array?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #11\n\nWhat is the time complexity of accessing the nth element of a singly linked list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #12\n\nWhat is the time complexity of “popping” an element in a queue if you are given a pointer to both the head and the tail of the queue?\n\n- [ ] O(2^n)\n\n- [ ] O(nlog(n))\n\n- [ ] O(1)\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n!)\n\n### Question #13\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(int n)\n{\n    int i;\n    int j;\n\n    for (i = 0; i \u003c n; i++)\n    {\n        if (i % 2 == 0)\n        {\n            for (j = 1; j \u003c n; j = j * 2)\n            {\n                printf(\"[%d] [%d]\\n\", i, j);\n            }\n        }\n        else\n        {\n            for (j = 0; j \u003c n; j = j + 2)\n            {\n                printf(\"[%d] [%d]\\n\", i, j);\n            }\n        }\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #14\n\nWhat is the best case time complexity of insertion in a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #15\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nint Fibonacci(int number)\n{\n    if (number \u003c= 1) return number;\n\n    return Fibonacci(number - 2) + Fibonacci(number - 1);\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #16\n\nWhat is the time complexity of removing at index n in an unsorted array?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #17\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(int n)\n{\n    printf(\"n = %d\\n\", n);\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #18\n\nWhat is the time complexity of accessing the nth element of a doubly linked list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #19\n\nAssuming you have a pointer to the node to set the value of, what is the time complexity of setting the value of the nth element in a doubly linked list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #20\n\nWhat is the time complexity of setting value at index n in an unsorted Python 3 list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #21\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(unsigned int n)\n{\n    int i;\n\n    for (i = 1; i \u003c n; i = i * 2)\n    {\n        printf(\"[%d]\\n\", i);\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #22\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(int n)\n{\n    int i;\n\n    for (i = 0; i \u003c n; i++)\n    {\n        printf(\"[%d]\\n\", i);\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #23\n\nWhat is the time complexity of removing at index n from an unsorted Python 3 list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #24\n\nWhat is the time complexity of this function / algorithm?\n\n```python\ndef func(n):\n    a=5\n    b=6\n    c=10\n    for i in range(n):\n        for j in range(n):\n            x = i * i\n            y = j * j\n            z = i * j\n    for k in range(n):\n        w = a*k + 45\n        v = b*b\n    d = 33\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #25\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(int n)\n{\n    int i;\n\n    for (i = 0; i \u003c n; i += 98)\n    {\n        printf(\"[%d]\\n\", i);\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #26\n\nWhat is the time complexity of best case deletion from a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #27\n\nWhat is the time complexity of this function / algorithm?\n\n```javascript\nvar factorial = function(n) {\n    if(n == 0) {\n        return 1\n    } else {\n        return n * factorial(n - 1);\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #28\n\nWhat is the worst case time complexity of insertion in a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #29\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(unsigned int n)\n{\n    int i;\n    int j;\n\n    for (i = 0; i \u003c n; i++)\n    {\n        for (j = 1; j \u003c n; j = j * 2)\n        {\n            printf(\"[%d] [%d]\\n\", i, j);\n        }\n    }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #30\n\nWhat is the best case time complexity searching for an element in a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #31\n\nWhat is the time complexity of this function / algorithm?\n\n```php\nforeach($numbers as $number)\n{\n    echo $number;\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #32\n\nWhat is the time complexity of inserting after the nth element of a singly linked list? (Assuming you have a pointer to the node to insert)\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #33\n\nWhat is the time complexity of setting the value of the nth element in a singly linked list? (Assuming you have a pointer to the node to set the value of)\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #34\n\nWhat is the time complexity of setting a value at index n in an unsorted array?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #35\n\nWhat is the time complexity of the “pop” operation onto a stack?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #36\n\nWhat is the time complexity accessing the nth element in an unsorted Python 3 list?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #37\n\nWhat is the time complexity of searching for an element - worst case - in a hash table with the implementation you used during the previous Hash Table C project (chaining)?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #38\n\nWhat is the time complexity of searching for an element in a queue of size n if you are given a pointer to both the head and the tail of the queue?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #39\n\nWhat is the time complexity of searching for an element in a doubly linked list of size n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #40\n\nWhat is the time complexity of searching for an element in an unsorted array of size n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #41\n\nWhat is the time complexity of this function / algorithm?\n\n```c\nvoid f(int n)\n{\n     int i;\n     int j;\n\n     for (i = 0; i \u003c n; i++)\n     {\n          for (j = i + 1; j \u003c n; j++)\n          {\n               printf(\"[%d] [%d]\\n\", i, j);\n          }\n     }\n}\n```\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n### Question #42\n\nWhat is the time complexity of searching for an element in an unsorted Python 3 list of size n?\n\n- [ ] O(2^n)\n\n- [ ] O(1)\n\n- [ ] O(nlog(n))\n\n- [ ] O(n)\n\n- [ ] O(log(n))\n\n- [ ] O(n^2)\n\n- [ ] O(n!)\n\n## Tasks\n\n### 0. Bubble sort\n\n[YouTube](https://www.youtube.com/watch?v=lyZQPjUT5B4)\n\nWrite a function that sorts an array of integers in ascending order using the [Bubble sort](https://en.wikipedia.org/wiki/Bubble_sort) algorithm\n\n- Prototype: `void bubble_sort(int *array, size_t size);`\n- You’re expected to print the `array` after each time you swap two elements (See example below)\n\nWrite in the file `0-O`, the big O notations of the time complexity of the Bubble sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 0-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    bubble_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 0-bubble_sort.c 0-main.c print_array.c -o bubble\nalex@/tmp/sort$ ./bubble\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n19, 48, 71, 99, 13, 52, 96, 73, 86, 7\n19, 48, 71, 13, 99, 52, 96, 73, 86, 7\n19, 48, 71, 13, 52, 99, 96, 73, 86, 7\n19, 48, 71, 13, 52, 96, 99, 73, 86, 7\n19, 48, 71, 13, 52, 96, 73, 99, 86, 7\n19, 48, 71, 13, 52, 96, 73, 86, 99, 7\n19, 48, 71, 13, 52, 96, 73, 86, 7, 99\n19, 48, 13, 71, 52, 96, 73, 86, 7, 99\n19, 48, 13, 52, 71, 96, 73, 86, 7, 99\n19, 48, 13, 52, 71, 73, 96, 86, 7, 99\n19, 48, 13, 52, 71, 73, 86, 96, 7, 99\n19, 48, 13, 52, 71, 73, 86, 7, 96, 99\n19, 13, 48, 52, 71, 73, 86, 7, 96, 99\n19, 13, 48, 52, 71, 73, 7, 86, 96, 99\n13, 19, 48, 52, 71, 73, 7, 86, 96, 99\n13, 19, 48, 52, 71, 7, 73, 86, 96, 99\n13, 19, 48, 52, 7, 71, 73, 86, 96, 99\n13, 19, 48, 7, 52, 71, 73, 86, 96, 99\n13, 19, 7, 48, 52, 71, 73, 86, 96, 99\n13, 7, 19, 48, 52, 71, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `0-bubble_sort.c, 0-O`\n\n### 1. Insertion sort\n\n[YouTube](https://www.youtube.com/watch?v=ROalU379l3U)\n\nWrite a function that sorts a doubly linked list of integers in ascending order using the [Insertion sort](https://en.wikipedia.org/wiki/Insertion_sort) algorithm\n\n- Prototype: `void insertion_sort_list(listint_t **list);`\n- You are not allowed to modify the integer `n` of a node. You have to swap the nodes themselves.\n- You’re expected to print the `list` after each time you swap two elements (See example below)\n\nWrite in the file `1-O`, the big O notations of the time complexity of the Insertion sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 1-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * create_listint - Creates a doubly linked list from an array of integers\n *\n * @array: Array to convert to a doubly linked list\n * @size: Size of the array\n *\n * Return: Pointer to the first element of the created list. NULL on failure\n */\nlistint_t *create_listint(const int *array, size_t size)\n{\n    listint_t *list;\n    listint_t *node;\n    int *tmp;\n\n    list = NULL;\n    while (size--)\n    {\n        node = malloc(sizeof(*node));\n        if (!node)\n            return (NULL);\n        tmp = (int *)\u0026node-\u003en;\n        *tmp = array[size];\n        node-\u003enext = list;\n        node-\u003eprev = NULL;\n        list = node;\n        if (list-\u003enext)\n            list-\u003enext-\u003eprev = list;\n    }\n    return (list);\n}\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    listint_t *list;\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    list = create_listint(array, n);\n    if (!list)\n        return (1);\n    print_list(list);\n    printf(\"\\n\");\n    insertion_sort_list(\u0026list);\n    printf(\"\\n\");\n    print_list(list);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 1-main.c 1-insertion_sort_list.c print_list.c -o insertion\nalex@/tmp/sort$ ./insertion\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n19, 48, 71, 99, 13, 52, 96, 73, 86, 7\n19, 48, 71, 13, 99, 52, 96, 73, 86, 7\n19, 48, 13, 71, 99, 52, 96, 73, 86, 7\n19, 13, 48, 71, 99, 52, 96, 73, 86, 7\n13, 19, 48, 71, 99, 52, 96, 73, 86, 7\n13, 19, 48, 71, 52, 99, 96, 73, 86, 7\n13, 19, 48, 52, 71, 99, 96, 73, 86, 7\n13, 19, 48, 52, 71, 96, 99, 73, 86, 7\n13, 19, 48, 52, 71, 96, 73, 99, 86, 7\n13, 19, 48, 52, 71, 73, 96, 99, 86, 7\n13, 19, 48, 52, 71, 73, 96, 86, 99, 7\n13, 19, 48, 52, 71, 73, 86, 96, 99, 7\n13, 19, 48, 52, 71, 73, 86, 96, 7, 99\n13, 19, 48, 52, 71, 73, 86, 7, 96, 99\n13, 19, 48, 52, 71, 73, 7, 86, 96, 99\n13, 19, 48, 52, 71, 7, 73, 86, 96, 99\n13, 19, 48, 52, 7, 71, 73, 86, 96, 99\n13, 19, 48, 7, 52, 71, 73, 86, 96, 99\n13, 19, 7, 48, 52, 71, 73, 86, 96, 99\n13, 7, 19, 48, 52, 71, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `1-insertion_sort_list.c, 1-O`\n\n### 2. Selection sort\n\n[YouTube](https://www.youtube.com/watch?v=Ns4TPTC8whw)\n\nWrite a function that sorts an array of integers in ascending order using the [Selection sort](https://en.wikipedia.org/wiki/Selection_sort) algorithm\n\n- Prototype: `void selection_sort(int *array, size_t size);`\n- You’re expected to print the `array` after each time you swap two elements (See example below)\n\nWrite in the file `2-O`, the big O notations of the time complexity of the Selection sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 2-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    selection_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89\n2-main.c 2-selection_sort.c print_array.c -o select\nalex@/tmp/sort$ ./select\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n7, 48, 99, 71, 13, 52, 96, 73, 86, 19\n7, 13, 99, 71, 48, 52, 96, 73, 86, 19\n7, 13, 19, 71, 48, 52, 96, 73, 86, 99\n7, 13, 19, 48, 71, 52, 96, 73, 86, 99\n7, 13, 19, 48, 52, 71, 96, 73, 86, 99\n7, 13, 19, 48, 52, 71, 73, 96, 86, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `2-selection_sort.c, 2-O`\n\n### 3. Quick sort\n\n[YouTube](https://www.youtube.com/watch?v=ywWBy6J5gz8)\n\nWrite a function that sorts an array of integers in ascending order using the [Quick sort](https://en.wikipedia.org/wiki/Quicksort) algorithm\n\n- Prototype: `void quick_sort(int *array, size_t size);`\n- You must implement the `Lomuto` partition scheme.\n- The pivot should always be the last element of the partition being sorted.\n- You’re expected to print the `array` after each time you swap two elements (See example below)\n\nWrite in the file `3-O`, the big O notations of the time complexity of the Quick sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 3-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    quick_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 3-main.c 3-quick_sort.c print_array.c -o quick\nalex@/tmp/sort$ ./quick\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n7, 48, 99, 71, 13, 52, 96, 73, 86, 19\n7, 13, 99, 71, 48, 52, 96, 73, 86, 19\n7, 13, 19, 71, 48, 52, 96, 73, 86, 99\n7, 13, 19, 71, 48, 52, 73, 96, 86, 99\n7, 13, 19, 71, 48, 52, 73, 86, 96, 99\n7, 13, 19, 48, 71, 52, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `3-quick_sort.c, 3-O`\n\n### 4. Shell sort - Knuth Sequence\n\nWrite a function that sorts an array of integers in ascending order using the [Shell sort](https://en.wikipedia.org/wiki/Shellsort) algorithm, using the `Knuth sequence`\n\n- Prototype: `void shell_sort(int *array, size_t size);`\n- You must use the following sequence of intervals (a.k.a the Knuth sequence):\n    - `n+1 = n * 3 + 1`\n    - `1, 4, 13, 40, 121, ...`\n- You’re expected to print the `array` each time you decrease the interval (See example below).\n\n**No big O notations of the time complexity of the Shell sort (Knuth sequence) algorithm needed - as the complexity is dependent on the size of array and gap**\n\n```bash\nalex@/tmp/sort$ cat 100-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    shell_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 100-main.c 100-shell_sort.c print_array.c -o shell\nalex@/tmp/sort$ ./shell\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n13, 7, 96, 71, 19, 48, 99, 73, 86, 52\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `100-shell_sort.c`\n\n### 5. Cocktail shaker sort\n\nWrite a function that sorts a doubly linked list of integers in ascending order using the [Cocktail shaker sort](https://en.wikipedia.org/wiki/Cocktail_shaker_sort) algorithm\n\n- Prototype: `void cocktail_sort_list(listint_t **list);`\n- You are not allowed to modify the integer `n` of a node. You have to swap the nodes themselves.\n- You’re expected to print the `list` after each time you swap two elements (See example below)\n\nWrite in the file `101-O`, the big O notations of the time complexity of the Cocktail shaker sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 101-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * create_listint - Creates a doubly linked list from an array of integers\n *\n * @array: Array to convert to a doubly linked list\n * @size: Size of the array\n *\n * Return: Pointer to the first element of the created list. NULL on failure\n */\nlistint_t *create_listint(const int *array, size_t size)\n{\n    listint_t *list;\n    listint_t *node;\n    int *tmp;\n\n    list = NULL;\n    while (size--)\n    {\n        node = malloc(sizeof(*node));\n        if (!node)\n            return (NULL);\n        tmp = (int *)\u0026node-\u003en;\n        *tmp = array[size];\n        node-\u003enext = list;\n        node-\u003eprev = NULL;\n        list = node;\n        if (list-\u003enext)\n            list-\u003enext-\u003eprev = list;\n    }\n    return (list);\n}\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    listint_t *list;\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    list = create_listint(array, n);\n    if (!list)\n        return (1);\n    print_list(list);\n    printf(\"\\n\");\n    cocktail_sort_list(\u0026list);\n    printf(\"\\n\");\n    print_list(list);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 101-main.c 101-cocktail_sort_list.c print_list.c -o cocktail\nalex@/tmp/sort$ ./cocktail\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n19, 48, 71, 99, 13, 52, 96, 73, 86, 7\n19, 48, 71, 13, 99, 52, 96, 73, 86, 7\n19, 48, 71, 13, 52, 99, 96, 73, 86, 7\n19, 48, 71, 13, 52, 96, 99, 73, 86, 7\n19, 48, 71, 13, 52, 96, 73, 99, 86, 7\n19, 48, 71, 13, 52, 96, 73, 86, 99, 7\n19, 48, 71, 13, 52, 96, 73, 86, 7, 99\n19, 48, 71, 13, 52, 96, 73, 7, 86, 99\n19, 48, 71, 13, 52, 96, 7, 73, 86, 99\n19, 48, 71, 13, 52, 7, 96, 73, 86, 99\n19, 48, 71, 13, 7, 52, 96, 73, 86, 99\n19, 48, 71, 7, 13, 52, 96, 73, 86, 99\n19, 48, 7, 71, 13, 52, 96, 73, 86, 99\n19, 7, 48, 71, 13, 52, 96, 73, 86, 99\n7, 19, 48, 71, 13, 52, 96, 73, 86, 99\n7, 19, 48, 13, 71, 52, 96, 73, 86, 99\n7, 19, 48, 13, 52, 71, 96, 73, 86, 99\n7, 19, 48, 13, 52, 71, 73, 96, 86, 99\n7, 19, 48, 13, 52, 71, 73, 86, 96, 99\n7, 19, 13, 48, 52, 71, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `101-cocktail_sort_list.c, 101-O`\n\n### 6. Counting sort\n\nWrite a function that sorts an array of integers in ascending order using the [Counting sort](https://en.wikipedia.org/wiki/Counting_sort) algorithm\n\n- Prototype: `void counting_sort(int *array, size_t size);`\nYou can assume that `array` will contain only numbers `\u003e= 0`\nYou are allowed to use `malloc` and `free` for this task\nYou’re expected to print your counting array once it is set up (See example below)\n    - This array is of size `k + 1` where `k` is the largest number in `array`\n\nWrite in the file `102-O`, the big O notations of the time complexity of the Counting sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 102-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    counting_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 102-main.c 102-counting_sort.c print_array.c -o counting\nalex@/tmp/sort$ ./counting\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 10\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `102-counting_sort.c, 102-O`\n\n### 7. Merge sort\n\nWrite a function that sorts an array of integers in ascending order using the [Merge sort](https://en.wikipedia.org/wiki/Merge_sort) algorithm\n\n- Prototype: `void merge_sort(int *array, size_t size);`\n- You must implement the top-down merge sort algorithm\n    - When you divide an array into two sub-arrays, the size of the left array should always be \u003c= the size of the right array. i.e. `{1, 2, 3, 4, 5}` -\u003e `{1, 2}, {3, 4, 5}`\n    - Sort the left array before the right array\n- You are allowed to use `printf`\n- You are allowed to use `malloc` and `free` only once (only one call)\n- Output: see example\n\nWrite in the file `103-O`, the big O notations of the time complexity of the Merge sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 103-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    merge_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 103-main.c 103-merge_sort.c print_array.c -o merge\nalex@/tmp/sort$ ./merge\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\nMerging...\n[left]: 19\n[right]: 48\n[Done]: 19, 48\nMerging...\n[left]: 71\n[right]: 13\n[Done]: 13, 71\nMerging...\n[left]: 99\n[right]: 13, 71\n[Done]: 13, 71, 99\nMerging...\n[left]: 19, 48\n[right]: 13, 71, 99\n[Done]: 13, 19, 48, 71, 99\nMerging...\n[left]: 52\n[right]: 96\n[Done]: 52, 96\nMerging...\n[left]: 86\n[right]: 7\n[Done]: 7, 86\nMerging...\n[left]: 73\n[right]: 7, 86\n[Done]: 7, 73, 86\nMerging...\n[left]: 52, 96\n[right]: 7, 73, 86\n[Done]: 7, 52, 73, 86, 96\nMerging...\n[left]: 13, 19, 48, 71, 99\n[right]: 7, 52, 73, 86, 96\n[Done]: 7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `103-merge_sort.c, 103-O`\n\n### 8. Heap sort\n\nWrite a function that sorts an array of integers in ascending order using the [Heap sort](https://en.wikipedia.org/wiki/Heapsort) algorithm\n\n- Prototype: `void heap_sort(int *array, size_t size);`\n- You must implement the `sift-down` heap sort algorithm\n- You’re expected to print the `array` after each time you swap two elements (See example below)\n\nWrite in the file `104-O`, the big O notations of the time complexity of the Heap sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 104-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    heap_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 104-main.c 104-heap_sort.c print_array.c -o heap\nalex@/tmp/sort$ ./heap\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n19, 48, 99, 86, 13, 52, 96, 73, 71, 7\n19, 86, 99, 48, 13, 52, 96, 73, 71, 7\n19, 86, 99, 73, 13, 52, 96, 48, 71, 7\n99, 86, 19, 73, 13, 52, 96, 48, 71, 7\n99, 86, 96, 73, 13, 52, 19, 48, 71, 7\n7, 86, 96, 73, 13, 52, 19, 48, 71, 99\n96, 86, 7, 73, 13, 52, 19, 48, 71, 99\n96, 86, 52, 73, 13, 7, 19, 48, 71, 99\n71, 86, 52, 73, 13, 7, 19, 48, 96, 99\n86, 71, 52, 73, 13, 7, 19, 48, 96, 99\n86, 73, 52, 71, 13, 7, 19, 48, 96, 99\n48, 73, 52, 71, 13, 7, 19, 86, 96, 99\n73, 48, 52, 71, 13, 7, 19, 86, 96, 99\n73, 71, 52, 48, 13, 7, 19, 86, 96, 99\n19, 71, 52, 48, 13, 7, 73, 86, 96, 99\n71, 19, 52, 48, 13, 7, 73, 86, 96, 99\n71, 48, 52, 19, 13, 7, 73, 86, 96, 99\n7, 48, 52, 19, 13, 71, 73, 86, 96, 99\n52, 48, 7, 19, 13, 71, 73, 86, 96, 99\n13, 48, 7, 19, 52, 71, 73, 86, 96, 99\n48, 13, 7, 19, 52, 71, 73, 86, 96, 99\n48, 19, 7, 13, 52, 71, 73, 86, 96, 99\n13, 19, 7, 48, 52, 71, 73, 86, 96, 99\n19, 13, 7, 48, 52, 71, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n13, 7, 19, 48, 52, 71, 73, 86, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `104-heap_sort.c, 104-O`\n\n### 9. Radix sort\n\nWrite a function that sorts an array of integers in ascending order using the [Radix sort](https://en.wikipedia.org/wiki/Radix_sort) algorithm\n\n- Prototype: `void radix_sort(int *array, size_t size);`\n- You must implement the `LSD` radix sort algorithm\n- You can assume that `array` will contain only numbers `\u003e= 0`\n- You are allowed to use `malloc` and `free` for this task\n- You’re expected to print the `array` each time you increase your `significant digit` (See example below)\n\n```bash\nalex@/tmp/sort$ cat 105-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    radix_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 105-main.c 105-radix_sort.c print_array.c -o radix\nalex@/tmp/sort$ ./radix\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n71, 52, 13, 73, 96, 86, 7, 48, 19, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `105-radix_sort.c`\n\n### 10. Bitonic sort\n\nWrite a function that sorts an array of integers in ascending order using the [Bitonic sort](https://en.wikipedia.org/wiki/Bitonic_sorter) algorithm\n\n- Prototype: `void bitonic_sort(int *array, size_t size);`\n- You can assume that `size` will be equal to `2^k`, where `k \u003e= 0` (when `array` is not `NULL` …)\n- You are allowed to use `printf`\n- You’re expected to print the `array` each time you swap two elements (See example below)\n- Output: see example\n\nWrite in the file `106-O`, the big O notations of the time complexity of the Bitonic sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 106-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {100, 93, 40, 57, 14, 58, 85, 54, 31, 56, 46, 39, 15, 26, 78, 13};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    bitonic_sort(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 106-main.c 106-bitonic_sort.c print_array.c -o bitonic\nalex@/tmp/sort$ ./bitonic\n100, 93, 40, 57, 14, 58, 85, 54, 31, 56, 46, 39, 15, 26, 78, 13\n\nMerging [16/16] (UP):\n100, 93, 40, 57, 14, 58, 85, 54, 31, 56, 46, 39, 15, 26, 78, 13\nMerging [8/16] (UP):\n100, 93, 40, 57, 14, 58, 85, 54\nMerging [4/16] (UP):\n100, 93, 40, 57\nMerging [2/16] (UP):\n100, 93\nResult [2/16] (UP):\n93, 100\nMerging [2/16] (DOWN):\n40, 57\nResult [2/16] (DOWN):\n57, 40\nResult [4/16] (UP):\n40, 57, 93, 100\nMerging [4/16] (DOWN):\n14, 58, 85, 54\nMerging [2/16] (UP):\n14, 58\nResult [2/16] (UP):\n14, 58\nMerging [2/16] (DOWN):\n85, 54\nResult [2/16] (DOWN):\n85, 54\nResult [4/16] (DOWN):\n85, 58, 54, 14\nResult [8/16] (UP):\n14, 40, 54, 57, 58, 85, 93, 100\nMerging [8/16] (DOWN):\n31, 56, 46, 39, 15, 26, 78, 13\nMerging [4/16] (UP):\n31, 56, 46, 39\nMerging [2/16] (UP):\n31, 56\nResult [2/16] (UP):\n31, 56\nMerging [2/16] (DOWN):\n46, 39\nResult [2/16] (DOWN):\n46, 39\nResult [4/16] (UP):\n31, 39, 46, 56\nMerging [4/16] (DOWN):\n15, 26, 78, 13\nMerging [2/16] (UP):\n15, 26\nResult [2/16] (UP):\n15, 26\nMerging [2/16] (DOWN):\n78, 13\nResult [2/16] (DOWN):\n78, 13\nResult [4/16] (DOWN):\n78, 26, 15, 13\nResult [8/16] (DOWN):\n78, 56, 46, 39, 31, 26, 15, 13\nResult [16/16] (UP):\n13, 14, 15, 26, 31, 39, 40, 46, 54, 56, 57, 58, 78, 85, 93, 100\n\n13, 14, 15, 26, 31, 39, 40, 46, 54, 56, 57, 58, 78, 85, 93, 100\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `106-bitonic_sort.c, 106-O`\n\n### 11. Quick Sort - Hoare Partition scheme\n\nWrite a function that sorts an array of integers in ascending order using the [Quick sort](https://en.wikipedia.org/wiki/Quicksort) algorithm\n\n- Prototype: `void quick_sort_hoare(int *array, size_t size);`\n- You must implement the `Hoare` partition scheme.\n- The pivot should always be the last element of the partition being sorted.\n- You’re expected to print the `array` after each time you swap two elements (See example below)\n\nWrite in the file `107-O`, the big O notations of the time complexity of the Quick sort algorithm, with 1 notation per line:\n\n- in the best case\n- in the average case\n- in the worst case\n\n```bash\nalex@/tmp/sort$ cat 107-main.c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"sort.h\"\n\n/**\n * main - Entry point\n *\n * Return: Always 0\n */\nint main(void)\n{\n    int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};\n    size_t n = sizeof(array) / sizeof(array[0]);\n\n    print_array(array, n);\n    printf(\"\\n\");\n    quick_sort_hoare(array, n);\n    printf(\"\\n\");\n    print_array(array, n);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 107-main.c 107-quick_sort_hoare.c print_array.c -o quick\nalex@/tmp/sort$ ./quick\n19, 48, 99, 71, 13, 52, 96, 73, 86, 7\n\n7, 48, 99, 71, 13, 52, 96, 73, 86, 19\n7, 19, 99, 71, 13, 52, 96, 73, 86, 48\n7, 19, 13, 71, 99, 52, 96, 73, 86, 48\n7, 13, 19, 71, 99, 52, 96, 73, 86, 48\n7, 13, 19, 48, 99, 52, 96, 73, 86, 71\n7, 13, 19, 48, 71, 52, 96, 73, 86, 99\n7, 13, 19, 48, 52, 71, 96, 73, 86, 99\n7, 13, 19, 48, 52, 71, 86, 73, 96, 99\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\n\n7, 13, 19, 48, 52, 71, 73, 86, 96, 99\nalex@/tmp/sort$\n```\n\nAnother example of output:\n\n```bash\nalex@/tmp/sort$ ./quick_2\n87, 65, 28, 63, 93, 52, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 16, 21, 75, 36, 71, 8, 45, 38\n\n38, 65, 28, 63, 93, 52, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 16, 21, 75, 36, 71, 8, 45, 87\n38, 8, 28, 63, 93, 52, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 16, 21, 75, 36, 71, 65, 45, 87\n38, 8, 28, 36, 93, 52, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 16, 21, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 52, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 16, 93, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 16, 39, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 11, 52, 93, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 16, 11, 59, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 26, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 16, 11, 26, 27, 30, 24, 83, 69, 62, 13, 6, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 16, 11, 26, 27, 30, 24, 6, 69, 62, 13, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n38, 8, 28, 36, 21, 16, 11, 26, 27, 30, 24, 6, 13, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n13, 8, 28, 36, 21, 16, 11, 26, 27, 30, 24, 6, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n13, 8, 6, 36, 21, 16, 11, 26, 27, 30, 24, 28, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n13, 8, 6, 11, 21, 16, 36, 26, 27, 30, 24, 28, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n11, 8, 6, 13, 21, 16, 36, 26, 27, 30, 24, 28, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 21, 16, 36, 26, 27, 30, 24, 28, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 21, 16, 28, 26, 27, 30, 24, 36, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 21, 16, 28, 26, 27, 24, 30, 36, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 21, 16, 24, 26, 27, 28, 30, 36, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 83, 88, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 87\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 83, 87, 58, 92, 59, 42, 39, 52, 93, 75, 63, 71, 65, 45, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 83, 87, 58, 45, 59, 42, 39, 52, 93, 75, 63, 71, 65, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 83, 87, 58, 45, 59, 42, 39, 52, 65, 75, 63, 71, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 71, 87, 58, 45, 59, 42, 39, 52, 65, 75, 63, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 69, 71, 63, 58, 45, 59, 42, 39, 52, 65, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 65, 71, 63, 58, 45, 59, 42, 39, 52, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 62, 65, 52, 63, 58, 45, 59, 42, 39, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 65, 52, 63, 58, 45, 59, 42, 62, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 62, 52, 63, 58, 45, 59, 42, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 62, 52, 42, 58, 45, 59, 63, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 59, 52, 42, 58, 45, 62, 63, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 45, 52, 42, 58, 59, 62, 63, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 45, 42, 52, 58, 59, 62, 63, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 42, 45, 52, 58, 59, 62, 63, 65, 71, 69, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 42, 45, 52, 58, 59, 62, 63, 65, 69, 71, 75, 87, 83, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 42, 45, 52, 58, 59, 62, 63, 65, 69, 71, 75, 83, 87, 93, 92, 88\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 42, 45, 52, 58, 59, 62, 63, 65, 69, 71, 75, 83, 87, 88, 92, 93\n\n6, 8, 11, 13, 16, 21, 24, 26, 27, 28, 30, 36, 38, 39, 42, 45, 52, 58, 59, 62, 63, 65, 69, 71, 75, 83, 87, 88, 92, 93\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `107-quick_sort_hoare.c, 107-O`\n\n### 12. Dealer\n\n[YouTube](https://www.youtube.com/watch?v=_HJlGWXzlLA)\n\nWrite a function that sorts a deck of cards.\n\n- Prototype: `void sort_deck(deck_node_t **deck);`\n- You are allowed to use the C standard library function `qsort`\n- Please use the following data structures:\n\n```c\ntypedef enum kind_e\n{\n    SPADE = 0,\n    HEART,\n    CLUB,\n    DIAMOND\n} kind_t;\n\n/**\n * struct card_s - Playing card\n *\n * @value: Value of the card\n * From \"Ace\" to \"King\"\n * @kind: Kind of the card\n */\ntypedef struct card_s\n{\n    const char *value;\n    const kind_t kind;\n} card_t;\n\n/**\n * struct deck_node_s - Deck of card\n *\n * @card: Pointer to the card of the node\n * @prev: Pointer to the previous node of the list\n * @next: Pointer to the next node of the list\n */\ntypedef struct deck_node_s\n{\n    const card_t *card;\n    struct deck_node_s *prev;\n    struct deck_node_s *next;\n} deck_node_t;\n```\n\n- You have to push you `deck.h` header file, containing the previous data structures definition\n- Each node of the doubly linked list contains a card that you cannot modify. You have to swap the nodes.\n- You can assume there is exactly `52` elements in the doubly linked list.\n- You are free to use the sorting algorithm of your choice\n- The deck must be ordered:\n    - From `Ace` to `King`\n    - From Spades to Diamonds\n    - See example below\n\n```bash\nalex@/tmp/sort$ cat 1000-main.c\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \"deck.h\"\n\nvoid print_deck(const deck_node_t *deck)\n{\n    size_t i;\n    char kinds[4] = {'S', 'H', 'C', 'D'};\n\n    i = 0;\n    while (deck)\n    {\n        if (i)\n            printf(\", \");\n        printf(\"{%s, %c}\", deck-\u003ecard-\u003evalue, kinds[deck-\u003ecard-\u003ekind]);\n        if (i == 12)\n            printf(\"\\n\");\n        i = (i + 1) % 13;\n        deck = deck-\u003enext;\n    }\n}\n\ndeck_node_t *init_deck(const card_t cards[52])\n{\n    deck_node_t *deck;\n    deck_node_t *node;\n    size_t i;\n\n    i = 52;\n    deck = NULL;\n    while (i--)\n    {\n        node = malloc(sizeof(*node));\n        if (!node)\n            return (NULL);\n        node-\u003ecard = \u0026cards[i];\n        node-\u003enext = deck;\n        node-\u003eprev = NULL;\n        if (deck)\n            deck-\u003eprev = node;\n        deck = node;\n    }\n    return (deck);\n}\n\nint main(void)\n{\n    card_t cards[52] = {\n        {\"Jack\", CLUB}, {\"4\", HEART}, {\"3\", HEART}, {\"3\", DIAMOND}, {\"Queen\", HEART}, {\"5\", HEART}, {\"5\", SPADE}, {\"10\", HEART}, {\"6\", HEART}, {\"5\", DIAMOND}, {\"6\", SPADE}, {\"9\", HEART}, {\"7\", DIAMOND}, {\"Jack\", SPADE}, {\"Ace\", DIAMOND}, {\"9\", CLUB}, {\"Jack\", DIAMOND}, {\"7\", SPADE}, {\"King\", DIAMOND}, {\"10\", CLUB}, {\"King\", SPADE}, {\"8\", CLUB}, {\"9\", SPADE}, {\"6\", CLUB}, {\"Ace\", CLUB}, {\"3\", SPADE}, {\"8\", SPADE}, {\"9\", DIAMOND}, {\"2\", HEART}, {\"4\", DIAMOND}, {\"6\", DIAMOND}, {\"3\", CLUB}, {\"Queen\", CLUB}, {\"10\", SPADE}, {\"8\", DIAMOND}, {\"8\", HEART}, {\"Ace\", SPADE}, {\"Jack\", HEART}, {\"2\", CLUB}, {\"4\", SPADE}, {\"2\", SPADE}, {\"2\", DIAMOND}, {\"King\", CLUB}, {\"Queen\", SPADE}, {\"Queen\", DIAMOND}, {\"7\", CLUB}, {\"7\", HEART}, {\"5\", CLUB}, {\"10\", DIAMOND}, {\"4\", CLUB}, {\"King\", HEART}, {\"Ace\", HEART},\n    };\n    deck_node_t *deck;\n\n    deck = init_deck(cards);\n    print_deck(deck);\n    printf(\"\\n\");\n    sort_deck(\u0026deck);\n    printf(\"\\n\");\n    print_deck(deck);\n    return (0);\n}\nalex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic  -std=gnu89 1000-main.c 1000-sort_deck.c -o deck\nalex@/tmp/sort$ ./deck\n{Jack, C}, {4, H}, {3, H}, {3, D}, {Queen, H}, {5, H}, {5, S}, {10, H}, {6, H}, {5, D}, {6, S}, {9, H}, {7, D}\n{Jack, S}, {Ace, D}, {9, C}, {Jack, D}, {7, S}, {King, D}, {10, C}, {King, S}, {8, C}, {9, S}, {6, C}, {Ace, C}, {3, S}\n{8, S}, {9, D}, {2, H}, {4, D}, {6, D}, {3, C}, {Queen, C}, {10, S}, {8, D}, {8, H}, {Ace, S}, {Jack, H}, {2, C}\n{4, S}, {2, S}, {2, D}, {King, C}, {Queen, S}, {Queen, D}, {7, C}, {7, H}, {5, C}, {10, D}, {4, C}, {King, H}, {Ace, H}\n\n\n{Ace, S}, {2, S}, {3, S}, {4, S}, {5, S}, {6, S}, {7, S}, {8, S}, {9, S}, {10, S}, {Jack, S}, {Queen, S}, {King, S}\n{Ace, H}, {2, H}, {3, H}, {4, H}, {5, H}, {6, H}, {7, H}, {8, H}, {9, H}, {10, H}, {Jack, H}, {Queen, H}, {King, H}\n{Ace, C}, {2, C}, {3, C}, {4, C}, {5, C}, {6, C}, {7, C}, {8, C}, {9, C}, {10, C}, {Jack, C}, {Queen, C}, {King, C}\n{Ace, D}, {2, D}, {3, D}, {4, D}, {5, D}, {6, D}, {7, D}, {8, D}, {9, D}, {10, D}, {Jack, D}, {Queen, D}, {King, D}\nalex@/tmp/sort$\n```\n\n**Repo:**\n- GitHub repository: `sorting_algorithms`\n- File: `1000-sort_deck.c, deck.h`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafara-n%2Fsorting_algorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftafara-n%2Fsorting_algorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftafara-n%2Fsorting_algorithms/lists"}