Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

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;




No comments:

Post a Comment