Sobes.tech
Intern — Middle

Getting the list in reverse order

livecode

Task condition

A singly linked list is given, where each node stores an integer value and a reference to the next element. It is required to write a function that creates and returns a new list with elements in reverse order relative to the original.

class Node {
    Node next;
    int value;
}

public Node reverse(Node root) {
    return null;
}