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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started