this is an example and i just need explanation private: struct Node { practice d
ID: 3752451 • Letter: T
Question
this is an example and i just need explanation
private:
struct Node {
practice data;
Node* next;
Node(practice m)
:data(m),
next(nullptr)
{
}
};
Node* head;
Node* tail;
int num;
public:
bool check(practice p) const;
//check to see if the same object is already present and return true,while traversing the linked list and is the same object was found
how would you do this
Explanation / Answer
bool Node::check(practice p) { Node *temp = head; // start at the head of the linked list while(temp != NULL) { // loop until end of the loop is reached. if(temp->data == p) { // if data at current node equals the input parameter, then return true return true; } temp = temp->next; // move to next node in the linked list } return false; // return false if value was not found in the linked list. } Explanation: ------------- Start at the head of the linked list. Go through each node in the linked list, if any node has the data that you are searching for, then return true. If data is not found in the linked list, then return false.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.