We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
the code in ur while loop is just unlinking the duplicate nodes, we've to delete them too as the problem statement demands"Delete duplicate-value nodes from a sorted linked list".
Correct code would be:
while ( nextItem != null && head.data == nextItem.data ) {
tmp = nextItem;
nextItem = nextItem.next;
delete tmp;
}
Delete duplicate-value nodes from a sorted linked list
You are viewing a single comment's thread. Return to all comments →
the code in ur while loop is just unlinking the duplicate nodes, we've to delete them too as the problem statement demands"Delete duplicate-value nodes from a sorted linked list". Correct code would be:
while ( nextItem != null && head.data == nextItem.data ) { tmp = nextItem; nextItem = nextItem.next; delete tmp; }