using recursion and recursive data structures. No loops please. Please help with return statements for isValid() and
Question:
using recursion and recursive data structures. No loops please.
Please help with return statements for isValid() and is ValidAdvanced()
public class Block { public int id; // Number public int rank; // position in the Chain public Block next;
// attributes to be added public int size;
public Block(int id, int rank) { this.id = id; this.rank = rank; this.next = null; // attributes to be added } public Block(int id, int rank, Block next) { this.id = id; this.rank = rank; this.next = next; // attributes to be added }
// Additional constructors may be added
// DO NOT MODIFY public String toString() { String str = "(" + id + ", " + rank + ")"; if (this.next == null) { return str; } return str + " -> " + next.toString(); } /** * * @return true if the chain starting at the current node is a valid Collatz * chain and false otherwise. For a chain to be valid, it needs to * follow the 3n+1 rule but not necessarily have a valid rank. The fast * collatz chain should be treated as invalid. */ public boolean isValid() { return false; /** * IMPORTANT: Even thought this method is in the Block class, it may be harder * than most in the Chain class. * * @return true if the chain starting at the current node is either a valid * Collatz chain or a fast Collatz chain. In this question, you also * need to ensure that the rank is valid. A valid rank starts at 1 and * increases with one. */ public boolean isValidAdvanced() { return false; } }