Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is an excerpt from the definition of a singly-linked list class. A LinkedLi

ID: 3826399 • Letter: H

Question

Here is an excerpt from the definition of a singly-linked list class. A LinkedList object represents a singly-linked list of integers. The implementation uses no dummy node, and the list end is indicated by the last node having NULL as its m_next data member. The empty list is represented by m_head and m_tail being NULL. class LinkedList {public: LinkedList();//creates an empty list void push_back(int v); void unique(); bool dominates (LinkedList & other) const {return dom(m_head, other.m_head);) private: struct Node {Node(int v, Node* n): m_value(v), m_next(n) {} int m_value; Node* m_ne times t;}; Node* m_head;//points to first Node in the list Node* m_tail;//points to last Node in the list bool dom(const Node* pi, const Node* p2) const;}; For this problem, we will ask you to write some function implementations. Be sure your code is syntactically correct as well as functionally correct. Notice that the Node type has no default constructor. The push_back function appends to the end of the list a node whose value is v. Write an implementation of this function in the space below.

Explanation / Answer

Here goes the required code for the pushback method of the single linked list given in the question

Code:

void push_back(int v){
   Node new;
   new.m_value=v;
   new.m_next=NULL;
   if(start==NULL){
       start=new;
   }
   else{
   temp=start;
   while(temp.m_next!=NULL){
       temp=temp.m_next;
   }
   temp.m_next=new;
   }
}

The funcion has a void return type as given in the problem and takes a parameter 'v' of type int which will be later stored in the m_data variable. Here I used start as the linked list name. You can replace it with your list name.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote