5. Delete Node #

Created Thursday 16 January 2020

  1. If trav = NULL or index<0. Do nothing.
  2. else If index 0. Special case. Easy

Node* p = head; head = head -> next; delete p; return head;

  1. For deleting the ith node, we need to go to the ith node and ensure that the ith node is not empty)

for(int i=0; i<index-1 && trav->next!=NULL; i++) // we are already at trav which is non null trav = trav->next; if(trav->next==NULL), i.e ith node is null or that our ll is short return head; Node* p = trav->next; // address of the ith node trav->next = p ->next; // p is not null, no errors here. delete p; return head;