Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created April 21, 2018 08:33
Show Gist options
  • Save Kishy-nivas/25c5747d25aa4cfdfe98dfb169266240 to your computer and use it in GitHub Desktop.
Save Kishy-nivas/25c5747d25aa4cfdfe98dfb169266240 to your computer and use it in GitHub Desktop.
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