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

Your Name: TA\'s Name: 16.(2 0 pts) In this problem you will be working with a d

ID: 3732578 • Letter: Y

Question

Your Name: TA's Name: 16.(2 0 pts) In this problem you will be working with a dynamically linked list. Given a class ListNode with the following private data members ListNode "pNext; string data; and a class ListNode with the following private data member: ListNode "pHead; and the class List is NOT a friend of class ListNode, write an appropriate insertInorder ( method that inserts strings in the order ('z' a'). The function should accept an argument, which is a reference to the string data object to insert. The method should return true if the data was inserted successfully; false otherwise. You may assume appropriate setters and getters are available for use. However, you may NOT assume that a makeNode () function or a constructor that accepts arguments exist. Listin sertInOrder (string new Data){ boo stafus Fatse bogl 09

Explanation / Answer

here is your code : ---------->>>>>>>>>

bool List::insertInOrder(string newData){
if(pHead == NULL){
  pHead = new ListNode;
  //here you can change this by actual setter getter method
  pHead.setData(newData);
  pHead.setNext(NULL);
  return true;
}
ListNode *tmp = new Node;
//here you can change this by actual setter getter method
tmp.setData(newData);
tmp.setNext(NULL);
ListNode *temp = pHead;
ListNode *prev = NULL;
while(temp != NULL){
  if(newData >= temp.getData()){
   if(prev == NULL){
    //here you can change this by actual setter getter method
    tmp.setNext(temp);
    pHead = tmp;
    return true;
   }else{
    //here you can change this by actual setter getter method
    prev.setNext(tmp);
    tmp.setNext(temp);
    return true;
   }
  }
  prev = temp;
  //here you can change this by actual setter getter method
  temp = temp.getNext();
}

return false;
}

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