Write these 5 functions for for class below: Please write the complete code usin
ID: 3787944 • Letter: W
Question
Write these 5 functions for for class below: Please write the complete code using C++ lanagauge.
1. deconstructor free all memmory on list List: ~List
2. delete oldest node instrted and return it's data value oldest node should be tail_ptr use int List:: pop
3. add a new node to end of the list, and newest node will be heald in head_ptr use void List::push(int new_data)
4. return if the node is containing the passed-in integer is in the list, true if such a node exists, false otherwise use bool List::search(int test_data)
5. remvoves the newest node containaing the passed in integers, only remove ONE node NOT ALL OF THEM. return true if any elements removed, false otherise. Use bool List:: remove(int old_data)
Below is the node.h file and the attahcemnet is the class file. Please help writting the 5 functions please comments on the line.
//This Node class is fully functional
class Node {
int data; //Holds the data we're keeping track of
Node *next;
public:
Node() {
data = 0;
next = NULL;
}
~Node() {
//You: Write a destructor here if you need one
}
Node(int new_data, Node *new_next) {
data = new_data;
next = new_next;
}
int get_data() const { return data; }
Node *get_next() const { return next; }
void set_next(Node *new_next) { next = new_next; }
};
Explanation / Answer
Find the five required functions below :
1. Destructor
~List() {
cou<< "destructor is called ";
int get_list_size() const {return list_size; }
}
2.
int List::pop() {
List::node *n_tail_ptr;
n_tail_ptr = tail_prt;
tail_ptr = tail_ptr->link();
int a;
int *no = a int[a1];
delete tail_ptr;
return ;
}
3.
void List::push(int new_data) {
head_ptr = new Node(1, head_ptr);
List *newnode = new List(NULL);
}
4.
bool List::search(int test_data) {
if(list_size) == List::data)
return true;
else
return false;
5.
(int old_data)
bool List::remove (int old_data) {
node *remove_prt;
remove_ptr = head_ptr;
head_ptr = head_ptr->link( );
delete remove_ptr;
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.