| 47 | class Solution |
| 48 | { |
| 49 | public ListNode reverseList(ListNode start) |
| 50 | { |
| 51 | if(start==null) |
| 52 | return null; |
| 53 | // if there is no elements in the linkedlist then it returns null |
| 54 | else |
| 55 | { |
| 56 | ListNode ptr,ptr1,ptr2; |
| 57 | for(ptr=null,ptr1=start,ptr2=start.next,ptr1.next=null;ptr2!=null;ptr2=ptr2.next,ptr1.next=ptr) |
| 58 | { |
| 59 | ptr=ptr1; |
| 60 | ptr1=ptr2; |
| 61 | } |
| 62 | start=ptr1; |
| 63 | return start; |
| 64 | // returns the start position of the linkedlist after reversing the list |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | // Solution class contains reverseList method which takes the start address as input and reverses the whole linkedlist |
| 69 | class ListNode |