Created
October 11, 2017 22:59
-
-
Save El-Sam/1d2078c28916e8e44a0dfc9064655f1c to your computer and use it in GitHub Desktop.
Revisions
-
El-Sam revised this gist
Oct 11, 2017 . No changes.There are no files selected for viewing
-
El-Sam created this gist
Oct 11, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ /* Reverse a linked list and return pointer to the head The input list will have at least one element Node is defined as class Node { int data; Node next; } */ Node Reverse(Node head) { if(head == null || head.next == null) return head; Node p = null; Node tail= null; while(head != null){ p = head.next; head.next = tail; tail = head; head = p; } return tail; }