Question: C++ Consider the following code: // Linked Lists: SEARCH for a given target in a list struct Data { int number; char ch; }; struct

C++

Consider the following code: // Linked Lists: SEARCH for a given target in a list

struct Data { int number; char ch; };

struct ListNode { Data data; struct ListNode *next; };

Assume that a linked list has been created and head points to a sentinel node. A sentinel node is an empty data node in the beginning of the list. It sometimes holds a sentinel value. The use of sentinel nodes is a popular trick to simplify the insert and delete operations.

You may also assume that the list is not empty and it is not sorted. The data in the sentinel node is -9999.

Write a function named searchList that is passed the pointer to the first node in the list and a target number. It searches for the target number in the list: if found, it copies the data to its outputparameter and returns true, otherwise returns false. A calling statement for this function is given below:

found = searchList(head, targetNumber, dataOut);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!