The following are class definitions for a singly-linked list of int values. You
ID: 3729425 • Letter: T
Question
The following are class definitions for a singly-linked list of int values. You should assume that the list does not use a dummy header. Also, note that the data members for Node are public. // The node used in List class Node f public: Node Node (int data); int n_data; Node* next; // List is a linked list of ints class List t public: // Creates a default empty list ListO // Creates a copy of another list List (const List other); // Destructor ListO // Assignment operator const List& operator=(const List krhs) ; // Insert "data" into the list void insert(int data); // Remove the last node in the linked list, if it exists Node removeLast // Return the umber of times that the value n appears int count(int n) private Node* _headerExplanation / Answer
int List::count(int n){
int m = 0;
Node *p = m_header;
while (p != NULL){
if (p->m_data == n)
m++;
p = p->m_next;
}
return m;
}
Node *copyList(Node *ptr){
Node *list ,*q, *r;
Node *p = ptr;
if (p == NULL)
return NULL;
list = NULL
while(p!= NULL){
r = new Node();
r->m_data = p->m_data;
r->m_next = NULL;
if (list == NULL){
list = r;
}
else {
q = list;
while (q->m_next != NULL){
q = q->m_next;
}
q->m_next = r;
}
p = p->m_next;
}
return list;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.