(start !=
nullptr) {
60std::cout <<
"->"<< start->data;
63std::cout << std::endl;
77 Node*head =
nullptr;
78 Node*tail =
nullptr;
79 for(
inti :
data) {
82 node->next =
nullptr;
83 if(head ==
nullptr) {
101voiddeleteList(
Node*
constroot) {
103deleteList(root->next);
116 if(sublist ==
nullptr|| mainList ==
nullptr) {
121 Node*target_ptr = sublist;
123 while(mainList !=
nullptr) {
125 Node*main_ptr = mainList;
127 while(target_ptr !=
nullptr) {
128 if(main_ptr ==
nullptr) {
131}
else if(main_ptr->
data== target_ptr->
data) {
134target_ptr = target_ptr->
next;
135main_ptr = main_ptr->
next;
142 if(target_ptr ==
nullptr) {
150target_ptr = sublist;
154mainList = mainList->
next;
175 template<
typenameT>
178std::cout <<
"[TESTS] : ---> "<< msg << std::endl;
187 log(
"Running Tests...");
193 log(
"Test Cases over!");
194std::cout << std::endl;
202 const boolexpectedOutput =
true;
204 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 206 log(
"This is test case 1 for sublist search Algorithm : ");
207 log(
"Description:");
208 log(
" EDGE CASE : Only contains one element");
210std::vector<uint64_t> sublistData = {
212std::vector<uint64_t> mainlistData = {
225sublistLL, mainlistLL);
227 log(
"Checking assert expression...");
228assert(exists == expectedOutput);
229 log(
"Assertion check passed!");
231 log(
"[PASS] : TEST CASE 1 PASS!");
232 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 235deleteList(mainlistLL);
236deleteList(sublistLL);
245 const boolexpectedOutput =
true;
247 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 249 log(
"This is test case 2 for sublist search Algorithm : ");
250 log(
"Description:");
251 log(
" contains main list of 100 elements and sublist of 20");
253std::vector<uint64_t> sublistData(
255std::vector<uint64_t> mainlistData(
258 for(
inti = 0; i < 100; i++) {
260mainlistData[i] = i + 1;
264 for(
inti = 45; i < 65; i++) {
266sublistData[temp] = i + 1;
279sublistLL, mainlistLL);
281 log(
"Checking assert expression...");
282assert(exists == expectedOutput);
283 log(
"Assertion check passed!");
285 log(
"[PASS] : TEST CASE 2 PASS!");
286 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 289deleteList(mainlistLL);
290deleteList(sublistLL);
299 const boolexpectedOutput =
false;
301 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 303 log(
"This is test case 3 for sublist search Algorithm : ");
304 log(
"Description:");
305 log(
" contains main list of 50 elements and sublist of 20");
307std::vector<uint64_t> sublistData(20);
308std::vector<uint64_t> mainlistData(
311 for(
inti = 0; i < 50; i++) {
313mainlistData.push_back(i + 1);
316 for(
inti = 45; i < 65; i++) {
318sublistData.push_back(i + 1);
330sublistLL, mainlistLL);
332 log(
"Checking assert expression...");
333assert(exists == expectedOutput);
334 log(
"Assertion check passed!");
336 log(
"[PASS] : TEST CASE 3 PASS!");
337 log(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 340deleteList(mainlistLL);
341deleteList(sublistLL);
361std::vector<uint64_t> mainlistData = {
363std::vector<uint64_t> sublistData = {6, 8};
376std::cout <<
"Sublist: "<< std::endl;
379std::cout <<
"Main list: "<< std::endl;
381std::cout << std::endl;
384std::cout <<
"[TRUE] - sublist found in main list\n";
386std::cout <<
"[FALSE] - sublist NOT found in main list\n";
389deleteList(mainlistLL);
390deleteList(sublistLL);
class encapsulating the necessary test cases
void log(T msg)
A function to print given message on console.
void testCase_2()
A test case which contains main list of 100 elements and sublist of 20.
void testCase_1()
A test case contains edge case, printing inorder successor of last node.
void testCase_3()
A test case which contains main list of 50 elements and sublist of 20.
void runTests()
Executes test cases.
Functions for the Sublist Search implementation.
A Node structure representing a single link Node in a linked list.
uint32_t data
the key/value of the node
Node * next
pointer to the next node
bool sublistSearch(Node *sublist, Node *mainList)
Main searching function.
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...
static void test()
Self-test implementations.
void printLinkedList(Node *start)
A simple function to print the linked list.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4