-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompression.diff
More file actions
192 lines (185 loc) · 7.03 KB
/
Copy pathcompression.diff
File metadata and controls
192 lines (185 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
--- input/input.cpp
+++ output/output.cpp
@@ -104,19 +104,8 @@
std::array<int64_t, size> arr, int64_t start, int64_t end) {
int64_t pivot = arr[end]; // Randomly selected element will be here from
// caller function (quickSortRP()).
- int64_t pInd = start;
-
- for (int64_t i = start; i < end; i++) {
- if (arr[i] <= pivot) {
- std::swap(arr[i], arr[pInd]); // swapping the elements from current
- // index to pInd.
- pInd++;
- }
- }
- std::swap(arr[pInd],
- arr[end]); // swapping the pivot element to its sorted position
+ { … 11 line(s) … ⟦tj:1a2e05f605c286abc0412df3ca5d9b6a⟧ }
return std::make_tuple(pInd, arr);
-}
/**
* @brief Random pivot quick sort function. This function is the starting point
@@ -131,23 +120,8 @@
int64_t start, int64_t end) {
if (start < end) {
int64_t randomIndex = getRandomIndex(start, end);
-
- // switching the pivot with right most bound.
- std::swap(arr[end], arr[randomIndex]);
-
- int64_t pivotIndex = 0;
- // getting pivot index and pivot sorted array.
- std::tie(pivotIndex, arr) = partition(arr, start, end);
-
- // Recursively calling
- std::array<int64_t, arr.size()> rightSortingLeft =
- quickSortRP(arr, start, pivotIndex - 1);
- std::array<int64_t, arr.size()> full_sorted =
- quickSortRP(rightSortingLeft, pivotIndex + 1, end);
- arr = full_sorted;
- }
+ { … 15 line(s) … ⟦tj:72008c3ac1ccc835b5eed1380a4f62df⟧ }
return arr;
-}
/**
* @brief A function utility to generate unsorted array of given size and range.
@@ -160,17 +134,8 @@
std::array<int64_t, size> generateUnsortedArray(int64_t from, int64_t to) {
srand(time(nullptr));
std::array<int64_t, size> unsortedArray{};
- assert(from < to);
- int64_t i = 0;
- while (i < size) {
- int64_t randomNum = from + rand() % (to - from + 1);
- if (randomNum) {
- unsortedArray[i] = randomNum;
- i++;
- }
- }
+ { … 9 line(s) … ⟦tj:a9a04ea89478305bfca34676a9a99506⟧ }
return unsortedArray;
-}
} // namespace random_pivot_quick_sort
} // namespace sorting
@@ -197,16 +162,8 @@
* @returns void
* */
void runTests() {
- log("Running Tests...");
+ { … 9 line(s) … ⟦tj:fc7ac61bfe85a66e570f0cedb7be1b73⟧ }
- testCase_1();
- testCase_2();
- testCase_3();
-
- log("Test Cases over!");
- std::cout << std::endl;
- }
-
/**
* @brief A test case with single input
* @returns void
@@ -214,29 +171,8 @@
void testCase_1() {
const int64_t inputSize = 1;
log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- "~");
- log("This is test case 1 for Random Pivot Quick Sort Algorithm : ");
- log("Description:");
- log(" EDGE CASE : Only contains one element");
- std::array<int64_t, inputSize> unsorted_arr{2};
-
- int64_t start = 0;
- int64_t end = unsorted_arr.size() - 1; // length - 1
-
- log("Running algorithm of data of length 50 ...");
- std::array<int64_t, unsorted_arr.size()> sorted_arr =
- sorting::random_pivot_quick_sort::quickSortRP(unsorted_arr, start,
- end);
- log("Algorithm finished!");
-
- log("Checking assert expression...");
- assert(std::is_sorted(sorted_arr.begin(), sorted_arr.end()));
- log("Assertion check passed!");
-
- log("[PASS] : TEST CASE 1 PASS!");
- log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ { … 21 line(s) … ⟦tj:0b6b1b423a94dc64c683aeb9572ca538⟧ }
"~");
- }
/**
* @brief A test case with input array of length 500
@@ -245,32 +181,9 @@
void testCase_2() {
const int64_t inputSize = 500;
log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ { … 23 line(s) … ⟦tj:550382bc1a7fa7872c0b445f6059ec40⟧ }
"~");
- log("Description:");
- log(" BIG INPUT : Contains 500 elements and repeated elements");
- log("This is test case 2 for Random Pivot Quick Sort Algorithm : ");
- std::array<int64_t, inputSize> unsorted_arr =
- sorting::random_pivot_quick_sort::generateUnsortedArray<inputSize>(
- 1, 10000);
- int64_t start = 0;
- int64_t end = unsorted_arr.size() - 1; // length - 1
-
- log("Running algorithm of data of length 500 ...");
- std::array<int64_t, unsorted_arr.size()> sorted_arr =
- sorting::random_pivot_quick_sort::quickSortRP(unsorted_arr, start,
- end);
- log("Algorithm finished!");
-
- log("Checking assert expression...");
- assert(std::is_sorted(sorted_arr.begin(), sorted_arr.end()));
- log("Assertion check passed!");
-
- log("[PASS] : TEST CASE 2 PASS!");
- log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- "~");
- }
-
/**
* @brief A test case with array of length 1000.
* @returns void
@@ -278,32 +191,8 @@
void testCase_3() {
const int64_t inputSize = 1000;
log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- "~");
- log("This is test case 3 for Random Pivot Quick Sort Algorithm : ");
- log("Description:");
- log(" LARGE INPUT : Contains 1000 elements and repeated elements");
- std::array<int64_t, inputSize> unsorted_arr =
- sorting::random_pivot_quick_sort::generateUnsortedArray<inputSize>(
- 1, 10000);
-
- int64_t start = 0;
- int64_t end = unsorted_arr.size() - 1; // length - 1
-
- log("Running algorithm...");
- std::array<int64_t, unsorted_arr.size()> sorted_arr =
- sorting::random_pivot_quick_sort::quickSortRP(unsorted_arr, start,
- end);
- log("Algorithm finished!");
-
- log("Checking assert expression...");
- assert(std::is_sorted(sorted_arr.begin(), sorted_arr.end()));
- log("Assertion check passed!");
-
- log("[PASS] : TEST CASE 3 PASS!");
- log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- "~");
+ { … 24 line(s) … ⟦tj:f66a4ebe63165ac2a32f124f2fadeb91⟧ }
}
-};
/**
* @brief Self-test implementations
@@ -335,3 +224,6 @@
sorting::random_pivot_quick_sort::showArray(sorted_array);
return 0;
}
+[omitted blocks are individually retrievable: call tinyjuice_retrieve with the token inside an omission marker to expand just that block]
+
+[PARTIAL view — full original (11901 bytes): call tinyjuice_retrieve with token "1869540b10d352171aec2f3218a6f216"]
\ No newline at end of file