From 1fc5a79d4fdbda88294c9914dd41a523175bc2a0 Mon Sep 17 00:00:00 2001 From: realstealthninja Date: Sat, 31 Aug 2024 00:39:17 +0000 Subject: [PATCH] Documentation for 8bde3ea612448b0d5fdbd2f092429e86de03ca62 --- d5/d45/sublist__search_8cpp.html | 194 ++++++++++++--------- d5/d58/class_test_cases.html | 284 ++++++++++++++++--------------- 2 files changed, 256 insertions(+), 222 deletions(-) diff --git a/d5/d45/sublist__search_8cpp.html b/d5/d45/sublist__search_8cpp.html index d2a64c76c..110659f0d 100644 --- a/d5/d45/sublist__search_8cpp.html +++ b/d5/d45/sublist__search_8cpp.html @@ -149,6 +149,8 @@ Functions Nodesearch::sublist_search::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 head pointer.
  +void search::sublist_search::deleteList (Node *const root) +  bool search::sublist_search::sublistSearch (Node *sublist, Node *mainList)  Main searching function.
  @@ -176,6 +178,29 @@ Working
Author
Nitin Sharma

Function Documentation

+ +

◆ deleteList()

+ +
+
+ + + + + + + +
void search::sublist_search::deleteList (Node *const root)
+
+
100 {
+
101 if (root != NULL) {
+
102 deleteList(root->next);
+
103 delete root;
+
104 }
+
105}
+
+
+

◆ main()

@@ -208,44 +233,47 @@ Working

< Sublist to be searched

< Main list in which sublist is to be searched

< boolean to check if the sublist exists or not

-
339 {
-
340 test(); // run self-test implementations
-
341
-
342 std::vector<uint64_t> mainlistData = {
-
343 2, 5, 6, 7, 8}; ///< Main list in which sublist is to be searched
-
344 std::vector<uint64_t> sublistData = {6, 8}; ///< Sublist to be searched
-
345
-
346 search::sublist_search::Node *mainlistLL =
- - - -
350 sublistData); ///< Main list in which sublist is to be
-
351 ///< searched
-
352
- -
354 sublistLL,
-
355 mainlistLL); ///< boolean to check if the sublist exists or not
-
356
-
357 std::cout << "Sublist: " << std::endl;
- -
359
-
360 std::cout << "Main list: " << std::endl;
- - -
363
-
364 if (exists) {
-
365 std::cout << "[TRUE] - sublist found in main list\n";
-
366 } else {
-
367 std::cout << "[FALSE] - sublist NOT found in main list\n";
-
368 }
-
369 return 0;
-
370}
+
359 {
+
360 test(); // run self-test implementations
+
361
+
362 std::vector<uint64_t> mainlistData = {
+
363 2, 5, 6, 7, 8}; ///< Main list in which sublist is to be searched
+
364 std::vector<uint64_t> sublistData = {6, 8}; ///< Sublist to be searched
+
365
+
366 search::sublist_search::Node *mainlistLL =
+ + + +
370 sublistData); ///< Main list in which sublist is to be
+
371 ///< searched
+
372
+ +
374 sublistLL,
+
375 mainlistLL); ///< boolean to check if the sublist exists or not
+
376
+
377 std::cout << "Sublist: " << std::endl;
+ +
379
+
380 std::cout << "Main list: " << std::endl;
+ + +
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}
T endl(T... args)
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 /// Initialize target pointer to the head node of sublist.
-
106 Node *target_ptr = sublist;
-
107
-
108 while (mainList != nullptr) {
-
109 /// Initialize main pointer to the current node of main list.
-
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 /// If the data of target node and main node is equal then move
-
118 /// to the next node of both lists.
-
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 /// Initialize target pointer to the head node of sublist.
+
120 Node *target_ptr = sublist;
121
-
122 } else {
-
123 break;
-
124 }
-
125 }
-
126
-
127 if (target_ptr == nullptr) {
-
128 /// Is target pointer becomes null that means the target list is
-
129 /// been traversed without returning false. Which means the sublist
-
130 /// has been found and return ture.
-
131 return true;
-
132 }
-
133
-
134 /// set the target pointer again to stating point of target list.
-
135 target_ptr = sublist;
-
136
-
137 /// set the main pointer to the next element of the main list and repeat
-
138 /// the algo.
-
139 mainList = mainList->next;
-
140 }
-
141
-
142 /// If the main list is exhausted, means sublist does not found, return
-
143 /// false
-
144 return false;
-
145}
+
122 while (mainList != nullptr) {
+
123 /// Initialize main pointer to the current node of main list.
+
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 /// If the data of target node and main node is equal then move
+
132 /// to the next node of both lists.
+
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 /// Is target pointer becomes null that means the target list is
+
143 /// been traversed without returning false. Which means the sublist
+
144 /// has been found and return ture.
+
145 return true;
+
146 }
+
147
+
148 /// set the target pointer again to stating point of target list.
+
149 target_ptr = sublist;
+
150
+
151 /// set the main pointer to the next element of the main list and repeat
+
152 /// the algo.
+
153 mainList = mainList->next;
+
154 }
+
155
+
156 /// If the main list is exhausted, means sublist does not found, return
+
157 /// false
+
158 return false;
+
159}
Here is the call graph for this function:
@@ -466,10 +494,10 @@ Here is the call graph for this function:

Self-test implementations.

Returns
void
-
328 {
-
329 TestCases tc;
-
330 tc.runTests();
-
331}
+
348 {
+
349 TestCases tc;
+
350 tc.runTests();
+
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
diff --git a/d5/d58/class_test_cases.html b/d5/d58/class_test_cases.html index e3aed0a3c..998abdb19 100644 --- a/d5/d58/class_test_cases.html +++ b/d5/d58/class_test_cases.html @@ -253,10 +253,10 @@ template<typename T >
Returns
void
-
161 {
-
162 // It's just to avoid writing cout and endl
-
163 std::cout << "[TESTS] : ---> " << msg << std::endl;
-
164 }
+
175 {
+
176 // It's just to avoid writing cout and endl
+
177 std::cout << "[TESTS] : ---> " << msg << std::endl;
+
178 }
Here is the call graph for this function:
@@ -382,16 +382,16 @@ Here is the call graph for this function:

Executes test cases.

Returns
void
-
171 {
-
172 log("Running Tests...");
-
173
-
174 testCase_1();
-
175 testCase_2();
-
176 testCase_3();
-
177
-
178 log("Test Cases over!");
- -
180 }
+
185 {
+
186 log("Running Tests...");
+
187
+
188 testCase_1();
+
189 testCase_2();
+
190 testCase_3();
+
191
+
192 log("Test Cases over!");
+ +
194 }
Here is the call graph for this function:
@@ -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; ///< Expected output of this test
-
188
-
189 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
190 "~");
-
191 log("This is test case 1 for sublist search Algorithm : ");
-
192 log("Description:");
-
193 log(" EDGE CASE : Only contains one element");
-
194
-
195 std::vector<uint64_t> sublistData = {
-
196 6}; ///< Data to make linked list which will be the sublist
-
197 std::vector<uint64_t> mainlistData = {
-
198 2, 5, 6, 7,
-
199 8}; ///< Data to make linked list which will be the main list
-
200
- - -
203 sublistData); ///< Sublist to be searched
-
204 search::sublist_search::Node *mainlistLL =
- -
206 mainlistData); ///< Main list in which sublist is to be
-
207 ///< searched
-
208
- -
210 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
-
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; ///< Expected output of this test
+
202
+
203 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
204 "~");
+
205 log("This is test case 1 for sublist search Algorithm : ");
+
206 log("Description:");
+
207 log(" EDGE CASE : Only contains one element");
+
208
+
209 std::vector<uint64_t> sublistData = {
+
210 6}; ///< Data to make linked list which will be the sublist
+
211 std::vector<uint64_t> mainlistData = {
+
212 2, 5, 6, 7,
+
213 8}; ///< Data to make linked list which will be the main list
+
214
+ + +
217 sublistData); ///< Sublist to be searched
+
218 search::sublist_search::Node *mainlistLL =
+ +
220 mainlistData); ///< Main list in which sublist is to be
+
221 ///< searched
+
222
+ +
224 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
+
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
@@ -778,51 +778,54 @@ 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

-
229 {
-
230 const bool expectedOutput = true; /// Expected output of this test
-
231
-
232 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
233 "~");
-
234 log("This is test case 2 for sublist search Algorithm : ");
-
235 log("Description:");
-
236 log(" contains main list of 100 elements and sublist of 20");
-
237
-
238 std::vector<uint64_t> sublistData(
-
239 20); ///< Data to make linked list which will be the sublist
-
240 std::vector<uint64_t> mainlistData(
-
241 100); ///< Main list in which sublist is to be searched
-
242
-
243 for (int i = 0; i < 100; i++) {
-
244 /// Inserts 100 elements in main list
-
245 mainlistData[i] = i + 1;
-
246 }
-
247
-
248 int temp = 0;
-
249 for (int i = 45; i < 65; i++) {
-
250 /// Inserts 20 elements in sublist
-
251 sublistData[temp] = i + 1;
-
252 temp++;
-
253 }
-
254
- - -
257 sublistData); ///< Sublist to be searched
-
258 search::sublist_search::Node *mainlistLL =
- -
260 mainlistData); ///< Main list in which sublist is to be
-
261 ///< searched
-
262
- -
264 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
-
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; /// Expected output of this test
+
245
+
246 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
247 "~");
+
248 log("This is test case 2 for sublist search Algorithm : ");
+
249 log("Description:");
+
250 log(" contains main list of 100 elements and sublist of 20");
+
251
+
252 std::vector<uint64_t> sublistData(
+
253 20); ///< Data to make linked list which will be the sublist
+
254 std::vector<uint64_t> mainlistData(
+
255 100); ///< Main list in which sublist is to be searched
+
256
+
257 for (int i = 0; i < 100; i++) {
+
258 /// Inserts 100 elements in main list
+
259 mainlistData[i] = i + 1;
+
260 }
+
261
+
262 int temp = 0;
+
263 for (int i = 45; i < 65; i++) {
+
264 /// Inserts 20 elements in sublist
+
265 sublistData[temp] = i + 1;
+
266 temp++;
+
267 }
+
268
+ + +
271 sublistData); ///< Sublist to be searched
+
272 search::sublist_search::Node *mainlistLL =
+ +
274 mainlistData); ///< Main list in which sublist is to be
+
275 ///< searched
+
276
+ +
278 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
+
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 }
Here is the call graph for this function:
@@ -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; ///< Expected output of this test
-
282
-
283 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
-
284 "~");
-
285 log("This is test case 3 for sublist search Algorithm : ");
-
286 log("Description:");
-
287 log(" contains main list of 50 elements and sublist of 20");
-
288
-
289 std::vector<uint64_t> sublistData(20); ///< Sublist to be searched
-
290 std::vector<uint64_t> mainlistData(
-
291 50); ///< Main list in which sublist is to be searched
-
292
-
293 for (int i = 0; i < 50; i++) {
-
294 /// Inserts 100 elements in main list
-
295 mainlistData.push_back(i + 1);
-
296 }
-
297
-
298 for (int i = 45; i < 65; i++) {
-
299 /// Inserts 20 elements in sublist
-
300 sublistData.push_back(i + 1);
-
301 }
-
302
- - -
305 sublistData); ///< Sublist to be searched
-
306 search::sublist_search::Node *mainlistLL =
- -
308 mainlistData); ///< Main list in which sublist is to be
-
309 ///< searched
-
310
- -
312 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
-
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; ///< Expected output of this test
+
299
+
300 log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+
301 "~");
+
302 log("This is test case 3 for sublist search Algorithm : ");
+
303 log("Description:");
+
304 log(" contains main list of 50 elements and sublist of 20");
+
305
+
306 std::vector<uint64_t> sublistData(20); ///< Sublist to be searched
+
307 std::vector<uint64_t> mainlistData(
+
308 50); ///< Main list in which sublist is to be searched
+
309
+
310 for (int i = 0; i < 50; i++) {
+
311 /// Inserts 100 elements in main list
+
312 mainlistData.push_back(i + 1);
+
313 }
+
314
+
315 for (int i = 45; i < 65; i++) {
+
316 /// Inserts 20 elements in sublist
+
317 sublistData.push_back(i + 1);
+
318 }
+
319
+ + +
322 sublistData); ///< Sublist to be searched
+
323 search::sublist_search::Node *mainlistLL =
+ +
325 mainlistData); ///< Main list in which sublist is to be
+
326 ///< searched
+
327
+ +
329 sublistLL, mainlistLL); ///< boolean, if sublist exist or not
+
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 }
Here is the call graph for this function: