TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of the Sublist Search Algorithm More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Classes | |
struct | search::sublist_search::Node |
A Node structure representing a single link Node in a linked list. More... | |
class | TestCases |
class encapsulating the necessary test cases More... | |
Namespaces | |
namespace | search |
for std::assert | |
namespace | sublist_search |
Functions for the Sublist Search implementation. | |
Functions | |
void | search::sublist_search::printLinkedList (Node *start) |
A simple function to print the linked list. | |
Node * | search::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. | |
static void | test () |
Self-test implementations. | |
int | main (int argc, char *argv[]) |
Main function. | |
Implementation of the Sublist Search Algorithm
Definition in file sublist_search.cpp.
void search::sublist_search::deleteList | ( | Node *const | root | ) |
Definition at line 101 of file sublist_search.cpp.
int main | ( | int | argc, |
char * | argv[] ) |
Main function.
argc | commandline argument count (ignored) |
argv | commandline array of arguments (ignored) |
< Main list in which sublist is to be searched
< Sublist to be searched
< Main list in which sublist is to be searched
< boolean to check if the sublist exists or not
Definition at line 360 of file sublist_search.cpp.
Node * search::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.
data | A vector of "int" containing the data that is supposed to be stored in nodes of linked list. |
This is used in test cases for rapidly creating linked list with 100+ elements, instead of hard-coding 100 elements in test cases.
Definition at line 74 of file sublist_search.cpp.
void search::sublist_search::printLinkedList | ( | Node * | start | ) |
A simple function to print the linked list.
start | The head of the linked list |
Definition at line 58 of file sublist_search.cpp.
Main searching function.
sublist | A linked list which is supposed to be searched in mainList. |
mainList | A linked list in which sublist will be searched. |
Initialize target pointer to the head node of sublist.
Initialize main pointer to the current node of main list.
If the data of target node and main node is equal then move to the next node of both lists.
Is target pointer becomes null that means the target list is been traversed without returning false. Which means the sublist has been found and return ture.
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
Definition at line 115 of file sublist_search.cpp.
|
static |
Self-test implementations.
Definition at line 349 of file sublist_search.cpp.