5. Insert a node a sorted linked list

5. Insert a node 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;




Disqus Comments