A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d5/d45/sublist__search_8cpp_source.html below:

TheAlgorithms/C++: search/sublist_search.cpp Source File

Go to the documentation of this file. 59 while

(start !=

nullptr

) {

60

std::cout <<

"->"

<< start->data;

63

std::cout << std::endl;

77 Node

*head =

nullptr

;

78 Node

*tail =

nullptr

;

79 for

(

int

i :

data

) {

82 node

->next =

nullptr

;

83 if

(head ==

nullptr

) {

101void

deleteList(

Node

*

const

root) {

103

deleteList(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

) {

134

target_ptr = target_ptr->

next

;

135

main_ptr = main_ptr->

next

;

142 if

(target_ptr ==

nullptr

) {

150

target_ptr = sublist;

154

mainList = mainList->

next

;

175 template

<

typename

T>

178

std::cout <<

"[TESTS] : ---> "

<< msg << std::endl;

187 log

(

"Running Tests..."

);

193 log

(

"Test Cases over!"

);

194

std::cout << std::endl;

202 const bool

expectedOutput =

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"

);

210

std::vector<uint64_t> sublistData = {

212

std::vector<uint64_t> mainlistData = {

225

sublistLL, mainlistLL);

227 log

(

"Checking assert expression..."

);

228

assert(exists == expectedOutput);

229 log

(

"Assertion check passed!"

);

231 log

(

"[PASS] : TEST CASE 1 PASS!"

);

232 log

(

"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 235

deleteList(mainlistLL);

236

deleteList(sublistLL);

245 const bool

expectedOutput =

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"

);

253

std::vector<uint64_t> sublistData(

255

std::vector<uint64_t> mainlistData(

258 for

(

int

i = 0; i < 100; i++) {

260

mainlistData[i] = i + 1;

264 for

(

int

i = 45; i < 65; i++) {

266

sublistData[temp] = i + 1;

279

sublistLL, mainlistLL);

281 log

(

"Checking assert expression..."

);

282

assert(exists == expectedOutput);

283 log

(

"Assertion check passed!"

);

285 log

(

"[PASS] : TEST CASE 2 PASS!"

);

286 log

(

"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 289

deleteList(mainlistLL);

290

deleteList(sublistLL);

299 const bool

expectedOutput =

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"

);

307

std::vector<uint64_t> sublistData(20);

308

std::vector<uint64_t> mainlistData(

311 for

(

int

i = 0; i < 50; i++) {

313

mainlistData.push_back(i + 1);

316 for

(

int

i = 45; i < 65; i++) {

318

sublistData.push_back(i + 1);

330

sublistLL, mainlistLL);

332 log

(

"Checking assert expression..."

);

333

assert(exists == expectedOutput);

334 log

(

"Assertion check passed!"

);

336 log

(

"[PASS] : TEST CASE 3 PASS!"

);

337 log

(

"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" 340

deleteList(mainlistLL);

341

deleteList(sublistLL);

361

std::vector<uint64_t> mainlistData = {

363

std::vector<uint64_t> sublistData = {6, 8};

376

std::cout <<

"Sublist: "

<< std::endl;

379

std::cout <<

"Main list: "

<< std::endl;

381

std::cout << std::endl;

384

std::cout <<

"[TRUE] - sublist found in main list\n"

;

386

std::cout <<

"[FALSE] - sublist NOT found in main list\n"

;

389

deleteList(mainlistLL);

390

deleteList(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