Ad
  • Custom User Avatar

    Oh awesome, thanks a lot for your effort!

  • Custom User Avatar
    public class Node {
      private Node next;
      
      public Node getNext() {
        return this.next;
      }
      
      private void setNext(Node next) {
        this.next = next;
      }
    
      public static Node createChain(int tailSize, int loopSize) {
        Node prevNode = new Node();
        Node start = prevNode;
        start.setNext(start);
        if (loopSize == 1) {
          return start;
        }
        for (int i = 1; i <= tailSize; ++i) {
          prevNode.setNext(new Node());
          prevNode = prevNode.getNext();
        }
        Node endLoop = prevNode;
        for (int i = 1; i < loopSize; ++i) {
          prevNode.setNext(new Node());
          prevNode = prevNode.getNext();
        }
        prevNode.setNext(endLoop);
        return start;
      }
    }
    
  • Custom User Avatar

    Oh sorry, I did not state I was trying to solve it in Java.
    Node also implements a util method to generate the full Structure Node.createChain(a, b);

  • Custom User Avatar
    function Node() {
      this.next;
      this.getNext = function() {
        return this.next
      // code
      }
      this.setNext = function(next) {
        this.next = next
      }
    }
    
  • Custom User Avatar

    No, it is not possible to run the tests locally in an IDE without the Node class.

  • Custom User Avatar

    The description contains following:

    // Use the `getNext()` method to get the following node.
    node.getNext()
    

    Is this not sufficient?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution