1. Write the method of the LinkList class to insert a new nodein the front of a
ID: 3611659 • Letter: 1
Question
1. Write the method of the LinkList class to insert a new nodein the front of a single linked list. 2. Write a method of the LinkedList to delete the last nodefrom a single linked list. 3. Write the method of the DoublyLinkedList class to findthe last node in a circular doubly linked list. 1. Write the method of the LinkList class to insert a new nodein the front of a single linked list. 2. Write a method of the LinkedList to delete the last nodefrom a single linked list. 3. Write the method of the DoublyLinkedList class to findthe last node in a circular doubly linked list.Explanation / Answer
I'll give you pseudo-ish code for 1 and 2. 1) Let Node* head be the current head node. Let Node* new_nodebe the node to insert. Node* temp = head; head = new_node; new_node->next = temp; 2) Let Node* head be the head node, Node* a declared. a = head. //get to the 2nd to last node. should check first to makesure the list is at least 3 nodes. i'll leave that foryou while((a->next)->next != NULL) a = a->next; //we're now at the 2nd to last node before the last node //deallocate memory of a->next here using delete/free dependingon the language a->next = NULL
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.