Posts Reverse a Linked List
Post
Cancel

Reverse a Linked List

PROBLEM DESCRIPTION

Reverse the LinkedList.

SOLUTION

snapshot

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static Node reverseLinkedList(Node head){

    Node h1=head;
    Node t=head;
    Node h2=null;

    while(h1 != null){
        h1 = h1.next;
        t.next = h2;
        h2 = t;
        t = h1;
    }

    return h2;

}
This post is licensed under CC BY 4.0 by the author.