359 {
+
+
361
+
+
363 2, 5, 6, 7, 8};
+
+
365
+
+
+
+
+
370 sublistData);
+
371
+
372
+
+
374 sublistLL,
+
375 mainlistLL);
+
376
+
+
+
379
+
+
+
+
383
+
384 if (exists) {
+
385 std::cout <<
"[TRUE] - sublist found in main list\n";
+
386 } else {
+
387 std::cout <<
"[FALSE] - sublist NOT found in main list\n";
+
388 }
+
389
+
390 deleteList(mainlistLL);
+
391 deleteList(sublistLL);
+
392 return 0;
+
393}
A Node structure representing a single link Node in a linked list.
Definition sublist_search.cpp:47
-
bool sublistSearch(Node *sublist, Node *mainList)
Main searching function.
Definition sublist_search.cpp:100
+
bool sublistSearch(Node *sublist, Node *mainList)
Main searching function.
Definition sublist_search.cpp:114
Node * makeLinkedList(const std::vector< uint64_t > &data)
Give a vector of data, it adds each element of vector in the linked list and return the address of he...
Definition sublist_search.cpp:73
-
static void test()
Self-test implementations.
Definition sublist_search.cpp:328
+
static void test()
Self-test implementations.
Definition sublist_search.cpp:348
void printLinkedList(Node *start)
A simple function to print the linked list.
Definition sublist_search.cpp:57
bool exists(const std::string &str, const std::unordered_set< std::string > &strSet)
Function that checks if the string passed in param is present in the the unordered_set passed.
Definition word_break.cpp:60
@@ -387,52 +415,52 @@ false if the sublist is NOT found
set the target pointer again to stating point of target list.
set the main pointer to the next element of the main list and repeat the algo.
If the main list is exhausted, means sublist does not found, return false
-
100 {
-
101 if (sublist == nullptr || mainList == nullptr) {
-
102 return false;
-
103 }
-
104
-
105
-
106 Node *target_ptr = sublist;
-
107
-
108 while (mainList != nullptr) {
-
109
-
110 Node *main_ptr = mainList;
-
111
-
112 while (target_ptr != nullptr) {
-
113 if (main_ptr == nullptr) {
-
114 return false;
-
115
-
116 } else if (main_ptr->data == target_ptr->data) {
-
117
-
118
-
119 target_ptr = target_ptr->next;
-
120 main_ptr = main_ptr->next;
+
114 {
+
115 if (sublist == nullptr || mainList == nullptr) {
+
116 return false;
+
117 }
+
118
+
119
+
120 Node *target_ptr = sublist;
121
-
122 } else {
-
123 break;
-
124 }
-
125 }
-
126
-
127 if (target_ptr == nullptr) {
-
128
-
129
-
130
-
131 return true;
-
132 }
-
133
-
134
-
135 target_ptr = sublist;
-
136
-
137
-
138
-
139 mainList = mainList->next;
-
140 }
-
141
-
142
-
143
-
144 return false;
-
145}
+
122 while (mainList != nullptr) {
+
123
+
124 Node *main_ptr = mainList;
+
125
+
126 while (target_ptr != nullptr) {
+
127 if (main_ptr == nullptr) {
+
128 return false;
+
129
+
130 } else if (main_ptr->data == target_ptr->data) {
+
131
+
132
+
133 target_ptr = target_ptr->next;
+
134 main_ptr = main_ptr->next;
+
135
+
136 } else {
+
137 break;
+
138 }
+
139 }
+
140
+
141 if (target_ptr == nullptr) {
+
142
+
143
+
144
+
145 return true;
+
146 }
+
147
+
148
+
149 target_ptr = sublist;
+
150
+
151
+
152
+
153 mainList = mainList->next;
+
154 }
+
155
+
156
+
157
+
158 return false;
+
159}
@@ -466,10 +494,10 @@ Here is the call graph for this function:
Self-test implementations.
- Returns
- void
-
328 {
-
-
-
331}
+
348 {
+
+
+
351}
class encapsulating the necessary test cases
Definition inorder_successor_of_bst.cpp:225
void runTests()
Executes test cases.
Definition inorder_successor_of_bst.cpp:243
- Returns
- void
-
161 {
-
162
-
-
164 }
+
@@ -382,16 +382,16 @@ Here is the call graph for this function:
Executes test cases.
- Returns
- void
-
171 {
-
172 log(
"Running Tests...");
-
173
-
-
-
-
177
-
178 log(
"Test Cases over!");
-
-
180 }
+
185 {
+
186 log(
"Running Tests...");
+
187
+
+
+
+
191
+
192 log(
"Test Cases over!");
+
+
194 }
@@ -557,45 +557,45 @@ Here is the call graph for this function:
< Sublist to be searched
< Main list in which sublist is to be searched
< boolean, if sublist exist or not
-
186 {
-
187 const bool expectedOutput = true;
-
188
-
189 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
190 "~");
-
191 log(
"This is test case 1 for sublist search Algorithm : ");
-
-
193 log(
" EDGE CASE : Only contains one element");
-
194
-
-
196 6};
-
-
198 2, 5, 6, 7,
-
199 8};
-
200
-
-
-
203 sublistData);
-
-
-
206 mainlistData);
-
207
-
208
-
-
210 sublistLL, mainlistLL);
-
211
-
212 log(
"Checking assert expression...");
-
213 assert(exists == expectedOutput);
-
214 log(
"Assertion check passed!");
-
215
-
216 log(
"[PASS] : TEST CASE 1 PASS!");
-
217 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
218 "~");
-
219
-
220 delete (sublistLL);
-
221 delete (mainlistLL);
-
222 }
+
200 {
+
201 const bool expectedOutput = true;
+
202
+
203 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
204 "~");
+
205 log(
"This is test case 1 for sublist search Algorithm : ");
+
+
207 log(
" EDGE CASE : Only contains one element");
+
208
+
+
210 6};
+
+
212 2, 5, 6, 7,
+
213 8};
+
214
+
+
+
217 sublistData);
+
+
+
220 mainlistData);
+
221
+
222
+
+
224 sublistLL, mainlistLL);
+
225
+
226 log(
"Checking assert expression...");
+
227 assert(exists == expectedOutput);
+
228 log(
"Assertion check passed!");
+
229
+
230 log(
"[PASS] : TEST CASE 1 PASS!");
+
231 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
232 "~");
+
233
+
234 deleteList(mainlistLL);
+
235 deleteList(sublistLL);
+
236 }
A Node structure representing a single link Node in a linked list.
Definition sublist_search.cpp:47
-
bool sublistSearch(Node *sublist, Node *mainList)
Main searching function.
Definition sublist_search.cpp:100
+
bool sublistSearch(Node *sublist, Node *mainList)
Main searching function.
Definition sublist_search.cpp:114
Node * makeLinkedList(const std::vector< uint64_t > &data)
Give a vector of data, it adds each element of vector in the linked list and return the address of he...
Definition sublist_search.cpp:73
bool exists(const std::string &str, const std::unordered_set< std::string > &strSet)
Function that checks if the string passed in param is present in the the unordered_set passed.
Definition word_break.cpp:60
< Sublist to be searched
< Main list in which sublist is to be searched
< boolean, if sublist exist or not
-
229 {
-
230 const bool expectedOutput = true;
-
231
-
232 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
233 "~");
-
234 log(
"This is test case 2 for sublist search Algorithm : ");
-
-
236 log(
" contains main list of 100 elements and sublist of 20");
-
237
-
-
239 20);
-
-
241 100);
-
242
-
243 for (int i = 0; i < 100; i++) {
-
244
-
245 mainlistData[i] = i + 1;
-
246 }
-
247
-
248 int temp = 0;
-
249 for (int i = 45; i < 65; i++) {
-
250
-
251 sublistData[temp] = i + 1;
-
252 temp++;
-
253 }
-
254
-
-
-
257 sublistData);
-
-
-
260 mainlistData);
-
261
-
262
-
-
264 sublistLL, mainlistLL);
-
265
-
266 log(
"Checking assert expression...");
-
267 assert(exists == expectedOutput);
-
268 log(
"Assertion check passed!");
-
269
-
270 log(
"[PASS] : TEST CASE 2 PASS!");
-
271 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
272 "~");
-
273 }
+
243 {
+
244 const bool expectedOutput = true;
+
245
+
246 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
247 "~");
+
248 log(
"This is test case 2 for sublist search Algorithm : ");
+
+
250 log(
" contains main list of 100 elements and sublist of 20");
+
251
+
+
253 20);
+
+
255 100);
+
256
+
257 for (int i = 0; i < 100; i++) {
+
258
+
259 mainlistData[i] = i + 1;
+
260 }
+
261
+
262 int temp = 0;
+
263 for (int i = 45; i < 65; i++) {
+
264
+
265 sublistData[temp] = i + 1;
+
266 temp++;
+
267 }
+
268
+
+
+
271 sublistData);
+
+
+
274 mainlistData);
+
275
+
276
+
+
278 sublistLL, mainlistLL);
+
279
+
280 log(
"Checking assert expression...");
+
281 assert(exists == expectedOutput);
+
282 log(
"Assertion check passed!");
+
283
+
284 log(
"[PASS] : TEST CASE 2 PASS!");
+
285 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
286 "~");
+
287
+
288 deleteList(mainlistLL);
+
289 deleteList(sublistLL);
+
290 }
@@ -1000,48 +1003,51 @@ Here is the call graph for this function:
< Sublist to be searched
< Main list in which sublist is to be searched
< boolean, if sublist exist or not
-
280 {
-
281 const bool expectedOutput = false;
-
282
-
283 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
284 "~");
-
285 log(
"This is test case 3 for sublist search Algorithm : ");
-
-
287 log(
" contains main list of 50 elements and sublist of 20");
-
288
-
-
-
291 50);
-
292
-
293 for (int i = 0; i < 50; i++) {
-
294
-
295 mainlistData.push_back(i + 1);
-
296 }
-
297
-
298 for (int i = 45; i < 65; i++) {
-
299
-
300 sublistData.push_back(i + 1);
-
301 }
-
302
-
-
-
305 sublistData);
-
-
-
308 mainlistData);
-
309
-
310
-
-
312 sublistLL, mainlistLL);
-
313
-
314 log(
"Checking assert expression...");
-
315 assert(exists == expectedOutput);
-
316 log(
"Assertion check passed!");
-
317
-
318 log(
"[PASS] : TEST CASE 3 PASS!");
-
319 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
320 "~");
-
321 }
+
297 {
+
298 const bool expectedOutput = false;
+
299
+
300 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
301 "~");
+
302 log(
"This is test case 3 for sublist search Algorithm : ");
+
+
304 log(
" contains main list of 50 elements and sublist of 20");
+
305
+
+
+
308 50);
+
309
+
310 for (int i = 0; i < 50; i++) {
+
311
+
312 mainlistData.push_back(i + 1);
+
313 }
+
314
+
315 for (int i = 45; i < 65; i++) {
+
316
+
317 sublistData.push_back(i + 1);
+
318 }
+
319
+
+
+
322 sublistData);
+
+
+
325 mainlistData);
+
326
+
327
+
+
329 sublistLL, mainlistLL);
+
330
+
331 log(
"Checking assert expression...");
+
332 assert(exists == expectedOutput);
+
333 log(
"Assertion check passed!");
+
334
+
335 log(
"[PASS] : TEST CASE 3 PASS!");
+
336 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
337 "~");
+
338
+
339 deleteList(mainlistLL);
+
340 deleteList(sublistLL);
+
341 }