From 15c9a91d8bf9071447468689a96d4cc5716d71c7 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 20 Feb 2023 22:49:53 +0000 Subject: [PATCH] Documentation for 5bf2c42bff08f215d73a2daf8d133b39765aef37 --- d2/d57/patience__sort_8c.html | 453 ++++++++++++++++++ d2/d57/patience__sort_8c.js | 8 + ...8dca7b867074164d5f45b0f3851269d_cgraph.map | 6 + ...8dca7b867074164d5f45b0f3851269d_cgraph.md5 | 1 + ...8dca7b867074164d5f45b0f3851269d_cgraph.svg | 66 +++ ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map | 7 + ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 | 1 + ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg | 81 ++++ ...0cc492037e002ba5145e2e770ed0e66_cgraph.map | 5 + ...0cc492037e002ba5145e2e770ed0e66_cgraph.md5 | 1 + ...0cc492037e002ba5145e2e770ed0e66_cgraph.svg | 51 ++ d5/d88/md__d_i_r_e_c_t_o_r_y.html | 4 + da/d11/patience__sort_8c__incl.map | 6 + da/d11/patience__sort_8c__incl.md5 | 1 + da/d11/patience__sort_8c__incl.svg | 66 +++ dir_bb1b521853a9c46347182a9d10420771.html | 3 + dir_bb1b521853a9c46347182a9d10420771.js | 1 + files.html | 7 +- globals_defs.html | 2 +- globals_func_m.html | 2 +- globals_func_p.html | 2 + globals_func_t.html | 3 +- globals_m.html | 4 +- globals_p.html | 2 + globals_t.html | 3 +- navtreedata.js | 8 +- navtreeindex0.js | 14 +- navtreeindex1.js | 18 +- navtreeindex2.js | 26 +- navtreeindex3.js | 24 +- navtreeindex4.js | 10 +- search/all_12.js | 91 ++-- search/all_16.js | 21 +- search/all_f.js | 6 +- search/files_10.js | 11 +- search/functions_10.js | 62 +-- search/functions_14.js | 9 +- search/functions_d.js | 2 +- 38 files changed, 935 insertions(+), 153 deletions(-) create mode 100644 d2/d57/patience__sort_8c.html create mode 100644 d2/d57/patience__sort_8c.js create mode 100644 d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.map create mode 100644 d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 create mode 100644 d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg create mode 100644 d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map create mode 100644 d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 create mode 100644 d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg create mode 100644 d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.map create mode 100644 d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.md5 create mode 100644 d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.svg create mode 100644 da/d11/patience__sort_8c__incl.map create mode 100644 da/d11/patience__sort_8c__incl.md5 create mode 100644 da/d11/patience__sort_8c__incl.svg diff --git a/d2/d57/patience__sort_8c.html b/d2/d57/patience__sort_8c.html new file mode 100644 index 00000000..b7d44f52 --- /dev/null +++ b/d2/d57/patience__sort_8c.html @@ -0,0 +1,453 @@ + + + + + + + +Algorithms_in_C: sorting/patience_sort.c File Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Algorithms_in_C 1.0.0 +
+
Set of algorithms implemented in C.
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+ +
patience_sort.c File Reference
+
+
+ +

Patience Sort +More...

+
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+Include dependency graph for patience_sort.c:
+
+
+
+
+
+ + + + + + + + + + + + + + + + +

+Functions

void patienceSort (int *array, int length)
 for assertions for IO operations for memory management
 
void printArray (int *array, int length)
 Helper function to print an array.
 
void testArray (int *array, int length)
 Testing Helper function.
 
static void test ()
 Self-test implementations.
 
int main ()
 Main function.
 
+

Detailed Description

+

Patience Sort

+

From Wikipedia: In computer science, patience sorting is a sorting algorithm inspired by, and named after, the card game patience. Given an array of n elements from some totally ordered domain, consider this array as a collection of cards and simulate the patience sorting game. When the game is over, recover the sorted sequence by repeatedly picking off the minimum visible card; in other words, perform a k-way merge of the p piles, each of which is internally sorted.

Author
CascadingCascade
+

Function Documentation

+ +

◆ main()

+ +
+
+ + + + + + + + +
int main (void )
+
+ +

Main function.

+
Returns
0 on exit
+
157 {
+
158 test(); // run self-test implementations
+
159 return 0;
+
160}
+
static void test()
Self-test implementations.
Definition: patience_sort.c:139
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ patienceSort()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void patienceSort (int * array,
int length 
)
+
+ +

for assertions for IO operations for memory management

+

Sorts the target array by dividing it into a variable number of internally sorted piles then merge the piles

Parameters
+ + + +
arraypointer to the array to be sorted
lengthlength of the target array
+
+
+
Returns
void
+
22 {
+
23 // An array of pointers used to store each pile
+
24 int* *piles = (int* *) malloc(sizeof(int*) * length);
+
25 for (int i = 0; i < length; ++i) {
+
26 piles[i] = malloc(sizeof(int) * length);
+
27 }
+
28
+
29 // pileSizes keep track of the indices of each pile's topmost element, hence 0 means only one element
+
30 // Note how calloc() is used to initialize the sizes of all piles to zero
+
31 int *pileSizes = (int*) calloc(length,sizeof(int));
+
32
+
33 // This initializes the first pile, note how using an array of pointers allowed us to access elements through two subscripts
+
34 // The first subscript indicates which pile we are accessing, the second subscript indicates the location being accessed in that pile
+
35 piles[0][0] = array[0];
+
36 int pileCount = 1;
+
37
+
38 for (int i = 1; i < length; ++i) {
+
39 // This will be used to keep track whether an element has been added to an existing pile
+
40 int flag = 1;
+
41
+
42 for (int j = 0; j < pileCount; ++j) {
+
43 if(piles[j][pileSizes[j]] > array[i]) {
+
44 // We have found a pile this element can be added to
+
45 piles[j][pileSizes[j] + 1] = array[i];
+
46 pileSizes[j]++;
+
47 flag--;
+
48 break;
+
49 }
+
50 }
+
51
+
52 if(flag) {
+
53 // The element in question can not be added to any existing piles, creating a new pile
+
54 piles[pileCount][0] = array[i];
+
55 pileCount++;
+
56 }
+
57 }
+
58
+
59 // This will keep track of the minimum value of all 'exposed' elements and which pile that value is from
+
60 int min, minLocation;
+
61
+
62 for (int i = 0; i < length; ++i) {
+
63 // Since there's no guarantee the first pile will be depleted slower than other piles,
+
64 // Example: when all elements are equal, in that case the first pile will be depleted immediately
+
65 // We can't simply initialize min to the top most element of the first pile,
+
66 // this loop finds a value to initialize min to.
+
67 for (int j = 0; j < pileCount; ++j) {
+
68 if(pileSizes[j] < 0) {
+
69 continue;
+
70 }
+
71 min = piles[j][pileSizes[j]];
+
72 minLocation = j;
+
73 break;
+
74 }
+
75
+
76 for (int j = 0; j < pileCount; ++j) {
+
77 if(pileSizes[j] < 0) {
+
78 continue;
+
79 }
+
80 if(piles[j][pileSizes[j]] < min) {
+
81 min = piles[j][pileSizes[j]];
+
82 minLocation = j;
+
83 }
+
84 }
+
85
+
86 array[i] = min;
+
87 pileSizes[minLocation]--;
+
88 }
+
89
+
90 // Deallocate memory
+
91 free(pileSizes);
+
92 for (int i = 0; i < length; ++i) {
+
93 free(piles[i]);
+
94 }
+
95 free(piles);
+
96}
+
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition: malloc_dbg.h:18
+
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition: malloc_dbg.h:26
+
#define calloc(elemCount, elemSize)
This macro replace the standard calloc function with calloc_dbg.
Definition: malloc_dbg.h:22
+
+
+
+ +

◆ printArray()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void printArray (int * array,
int length 
)
+
+ +

Helper function to print an array.

+
Parameters
+ + + +
arraypointer to the array
lengthlength of the target array
+
+
+
Returns
void
+
104 {
+
105 printf("Array:");
+
106 for (int i = 0; i < length; ++i) {
+
107 printf("%d",array[i]);
+
108 if (i != length - 1) putchar(',');
+
109 }
+
110 putchar('\n');
+
111}
+
+
+
+ +

◆ test()

+ +
+
+ + + + + +
+ + + + + + + + +
static void test (void )
+
+static
+
+ +

Self-test implementations.

+
Returns
void
+
139 {
+
140 int testArray1[] = {2,8,7,1,3,5,6,4};
+
141 int testArray2[] = {2,2,5,1,3,5,6,4};
+
142 int testArray3[] = {1,2,3,4,5,6,7,8};
+
143 int testArray4[] = {8,7,6,5,4,3,2,1};
+
144
+
145 testArray(testArray1,8);
+
146 testArray(testArray2,8);
+
147 testArray(testArray3,8);
+
148 testArray(testArray4,8);
+
149
+
150 printf("Testing successfully completed!\n");
+
151}
+
void testArray(int *array, int length)
Testing Helper function.
Definition: patience_sort.c:120
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ testArray()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void testArray (int * array,
int length 
)
+
+ +

Testing Helper function.

+
Parameters
+ + + +
arraypointer to the array to be used for testing
lengthlength of the target array
+
+
+
Returns
void
+
120 {
+
121 printf("Before sorting:\n");
+
122 printArray(array,length);
+
123
+
124 patienceSort(array,length);
+
125
+
126 printf("After sorting:\n");
+
127 printArray(array,length);
+
128
+
129 for (int i = 0; i < length - 1; ++i) {
+
130 assert(array[i] <= array[i + 1]);
+
131 }
+
132 printf("All assertions have passed!\n\n");
+
133}
+
void printArray(int *array, int length)
Helper function to print an array.
Definition: patience_sort.c:104
+
void patienceSort(int *array, int length)
for assertions for IO operations for memory management
Definition: patience_sort.c:22
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+
+
+ + + + diff --git a/d2/d57/patience__sort_8c.js b/d2/d57/patience__sort_8c.js new file mode 100644 index 00000000..70da8d3e --- /dev/null +++ b/d2/d57/patience__sort_8c.js @@ -0,0 +1,8 @@ +var patience__sort_8c = +[ + [ "main", "d2/d57/patience__sort_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ], + [ "patienceSort", "d2/d57/patience__sort_8c.html#a5ce3f8e766a38377168ae737605745c8", null ], + [ "printArray", "d2/d57/patience__sort_8c.html#a51db6714f25747b7de0daca675363e19", null ], + [ "test", "d2/d57/patience__sort_8c.html#aa8dca7b867074164d5f45b0f3851269d", null ], + [ "testArray", "d2/d57/patience__sort_8c.html#af0cc492037e002ba5145e2e770ed0e66", null ] +]; \ No newline at end of file diff --git a/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 00000000..4ad1c7e0 --- /dev/null +++ b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 00000000..05f2217d --- /dev/null +++ b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +5b8e810640a93574216ead163fcf27a3 \ No newline at end of file diff --git a/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 00000000..0352365c --- /dev/null +++ b/d2/d57/patience__sort_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,66 @@ + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +testArray + + + + + +Node1->Node2 + + + + + +Node3 + + +patienceSort + + + + + +Node2->Node3 + + + + + +Node4 + + +printArray + + + + + +Node2->Node4 + + + + + diff --git a/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map new file mode 100644 index 00000000..7ec65b84 --- /dev/null +++ b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -0,0 +1,7 @@ + + + + + + + diff --git a/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 new file mode 100644 index 00000000..86cbb055 --- /dev/null +++ b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -0,0 +1 @@ +dd40d0d5bc28325b41868385d9ccd6c6 \ No newline at end of file diff --git a/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg new file mode 100644 index 00000000..fcdaccd8 --- /dev/null +++ b/d2/d57/patience__sort_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -0,0 +1,81 @@ + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + +Node3 + + +testArray + + + + + +Node2->Node3 + + + + + +Node4 + + +patienceSort + + + + + +Node3->Node4 + + + + + +Node5 + + +printArray + + + + + +Node3->Node5 + + + + + diff --git a/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.map b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.map new file mode 100644 index 00000000..2dcbbd7a --- /dev/null +++ b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.md5 b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.md5 new file mode 100644 index 00000000..15aed984 --- /dev/null +++ b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.md5 @@ -0,0 +1 @@ +49a5b182b42aaa3ee1b5d8191d1c1669 \ No newline at end of file diff --git a/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.svg b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.svg new file mode 100644 index 00000000..d7bcc8d8 --- /dev/null +++ b/d2/d57/patience__sort_8c_af0cc492037e002ba5145e2e770ed0e66_cgraph.svg @@ -0,0 +1,51 @@ + + + + + + +testArray + + +Node1 + + +testArray + + + + + +Node2 + + +patienceSort + + + + + +Node1->Node2 + + + + + +Node3 + + +printArray + + + + + +Node1->Node3 + + + + + diff --git a/d5/d88/md__d_i_r_e_c_t_o_r_y.html b/d5/d88/md__d_i_r_e_c_t_o_r_y.html index 5fd5d1fd..a9d1f795 100644 --- a/d5/d88/md__d_i_r_e_c_t_o_r_y.html +++ b/d5/d88/md__d_i_r_e_c_t_o_r_y.html @@ -432,6 +432,7 @@ Leetcode
  • 520
  • 53
  • 561
  • +
  • 567
  • 6
  • 617
  • 62
  • @@ -463,8 +464,10 @@ Leetcode
  • 931
  • 938
  • 94
  • +
  • 953
  • 965
  • 977
  • +
  • 979
  • 98
  • 985
  • 997
  • @@ -703,6 +706,7 @@ Sorting
  • Odd Even Sort
  • Pancake Sort
  • Partition Sort
  • +
  • Patience Sort
  • Pigeonhole Sort
  • Quick Sort
  • Radix Sort
  • diff --git a/da/d11/patience__sort_8c__incl.map b/da/d11/patience__sort_8c__incl.map new file mode 100644 index 00000000..4451e2a7 --- /dev/null +++ b/da/d11/patience__sort_8c__incl.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/da/d11/patience__sort_8c__incl.md5 b/da/d11/patience__sort_8c__incl.md5 new file mode 100644 index 00000000..ea4c2280 --- /dev/null +++ b/da/d11/patience__sort_8c__incl.md5 @@ -0,0 +1 @@ +e944d7acc0627b30b6314098fbead90f \ No newline at end of file diff --git a/da/d11/patience__sort_8c__incl.svg b/da/d11/patience__sort_8c__incl.svg new file mode 100644 index 00000000..0d6d48b1 --- /dev/null +++ b/da/d11/patience__sort_8c__incl.svg @@ -0,0 +1,66 @@ + + + + + + +sorting/patience_sort.c + + +Node1 + + +sorting/patience_sort.c + + + + + +Node2 + + +assert.h + + + + + +Node1->Node2 + + + + + +Node3 + + +stdio.h + + + + + +Node1->Node3 + + + + + +Node4 + + +stdlib.h + + + + + +Node1->Node4 + + + + + diff --git a/dir_bb1b521853a9c46347182a9d10420771.html b/dir_bb1b521853a9c46347182a9d10420771.html index da59e575..817f6d56 100644 --- a/dir_bb1b521853a9c46347182a9d10420771.html +++ b/dir_bb1b521853a9c46347182a9d10420771.html @@ -130,6 +130,9 @@ Files file  odd_even_sort.c  Odd Even Sort implementation
      +file  patience_sort.cPatience Sort
    +  file  selection_sort.c  Selection sort algorithm implementation.
      diff --git a/dir_bb1b521853a9c46347182a9d10420771.js b/dir_bb1b521853a9c46347182a9d10420771.js index e8eac86c..f99088fe 100644 --- a/dir_bb1b521853a9c46347182a9d10420771.js +++ b/dir_bb1b521853a9c46347182a9d10420771.js @@ -9,6 +9,7 @@ var dir_bb1b521853a9c46347182a9d10420771 = [ "insertion_sort_recursive.c", "de/d0c/insertion__sort__recursive_8c.html", "de/d0c/insertion__sort__recursive_8c" ], [ "merge_sort.c", "d2/d83/merge__sort_8c.html", "d2/d83/merge__sort_8c" ], [ "odd_even_sort.c", "d1/d94/odd__even__sort_8c.html", "d1/d94/odd__even__sort_8c" ], + [ "patience_sort.c", "d2/d57/patience__sort_8c.html", "d2/d57/patience__sort_8c" ], [ "selection_sort.c", "df/d83/selection__sort_8c.html", "df/d83/selection__sort_8c" ], [ "selection_sort_recursive.c", "dc/d39/selection__sort__recursive_8c.html", "dc/d39/selection__sort__recursive_8c" ], [ "shell_sort2.c", "d6/ded/shell__sort2_8c.html", "d6/ded/shell__sort2_8c" ] diff --git a/files.html b/files.html index d0c1ed4f..ae1d2d42 100644 --- a/files.html +++ b/files.html @@ -305,9 +305,10 @@ $(document).ready(function(){initNavTree('files.html',''); initResizable(); });  insertion_sort_recursive.cInsertion sort algorithm implementation  merge_sort.cImplementation of merge sort algorithm  odd_even_sort.cOdd Even Sort implementation - selection_sort.cSelection sort algorithm implementation - selection_sort_recursive.cSelection Sort implementation using recursion - shell_sort2.cShell sort algorithm implementation + patience_sort.cPatience Sort + selection_sort.cSelection sort algorithm implementation + selection_sort_recursive.cSelection Sort implementation using recursion + shell_sort2.cShell sort algorithm implementation diff --git a/globals_defs.html b/globals_defs.html index bc22b2b6..b50bdf79 100644 --- a/globals_defs.html +++ b/globals_defs.html @@ -144,8 +144,8 @@ $(document).ready(function(){initNavTree('globals_defs.html',''); initResizable(

    - m -