Labels

algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)

Reversing a Linked List

    private static void reverseLinkedList(MyLinkedList linkedList) {
        Node current = linkedList.head;
        Node previous = null;
        Node next = null;
        while (current != null) {
            next = current.next;
            current.next = previous;
            previous = current;
            current = next;
        }
        linkedList.head = previous;
    }

No comments:

Post a Comment

Search 24 Bytes

Loading...