function that Search for a given number. If the number is available, then your p
ID: 3620771 • Letter: F
Question
function that Search for a given number. If the number is available, then your program print that number and specify its position in the linked list. If the number not found, your program must print the following message" Your number is not found. Try another number". It is important to note that, if the searched number available in more than one position, your program must show these positions.i do it but how i can make program show the position
template <class t>
bool singlelinklist<t> ::search(const t& searchitem) ////**
{
nodetype<t> *current;
bool found = false;
current = first;
int c=0;
while (current !=NULL && !found )
if (current->info==searchitem)
{
found =true;
c++;
}
else
current =current->link;
return found;
}
Explanation / Answer
bool linkedListType::search(const Type& searchItem) const { nodeType *current; //pointer to traverse the list bool found = false; current = first; //set current to point to the first //node in the list int position=0; while (current != NULL) //search the list { position++; if (current->info == searchItem) //searchItem is found { found = true; current = current->link; //make current point to the next node coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.