Popular Posts

Thursday, March 17, 2011

Remove all the nodes which have a greater value on right side in Linked list

Given a linked list, remove all the nodes which have a greater value on right side.
Eg :  the list 12->15->10->11->5->6->2->3
should be changed to 15->11->6->3
Algo : O(n)
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