How to insert a node into a sorted linked list

void sortedInsert(Node * head, Node * newNode) {
  Node * current = head;

  // traverse the list until you find item bigger the // new node value
  //	
  while (current != NULL && current -> data < newNode -> data) {
    current = current -> next);
}
//
// insert the new node before the big item
//
newNode -> next = current -> next;
current = newNode;
}
Chitra
Chitra

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in