Given a linked list, remove all the nodes which have a greater value on right side.
1. Reverse the list.
2. Keep max till now. if next node < max then delete the node, otherwise max = next node.
3. Reverse the list again.
Refer : http://www.geeksforgeeks.org/archives/11604
http://geeksforgeeks.org/?p=3511
Eg : the list 12->15->10->11->5->6->2->3
should be changed to 15->11->6->3
Algo : O(n)should be changed to 15->11->6->3
1. Reverse the list.
2. Keep max till now. if next node < max then delete the node, otherwise max = next node.
3. Reverse the list again.
Refer : http://www.geeksforgeeks.org/archives/11604
http://geeksforgeeks.org/?p=3511
No comments:
Post a Comment