// Assuming that Linked List is sorted in ascending order.
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->link);
}
// insert the new node before the big item
newNode->link = current->link;
current = newNode;
}
No comments:
Post a Comment