Created
April 21, 2018 08:33
-
-
Save Kishy-nivas/25c5747d25aa4cfdfe98dfb169266240 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GfG | |
{ | |
Node reverse(Node head){ | |
Node curr = head; | |
Node prev = null; | |
Node next; | |
while(curr != null){ | |
next = curr.next; | |
curr.next =prev; | |
prev = curr; | |
curr = next; | |
} | |
return prev; | |
} | |
void compute(LinkedList l) | |
{ | |
Node reverse_head = reverse(l.head); | |
Node curr =reverse_head; | |
while(curr != null){ | |
if(curr.next !=null && curr.data > curr.next.data){ | |
curr.next = curr.next.next; | |
} | |
else{ | |
curr = curr.next; | |
} | |
} | |
Node original_head = reverse(reverse_head); | |
l.head =original_head; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment