fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Nested<A> {
  8. public A left;
  9. public Nested<List<A>> right;
  10. public Nested(A l, Nested<List<A>> r) {
  11. left = l;
  12. right = r;
  13. }
  14. }
  15.  
  16. class Ideone
  17. {
  18. static <A> int length(Nested<A> xs) {
  19. if (xs == null) {
  20. return 0;
  21. } else {
  22. return 1 + length(xs.right);
  23. }
  24. }
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. List<Integer> l234 = Arrays.asList(2, 3, 4);
  28. List<Integer> l56 = Arrays.asList(5, 6);
  29. List<Integer> l7 = Arrays.asList(7);
  30. List<List<Integer>> l567 = Arrays.asList(l56, l7);
  31. Nested<Integer> nested =
  32. new Nested(
  33. 1,
  34. new Nested(
  35. l234,
  36. new Nested(
  37. l567,
  38. null
  39. )
  40. )
  41. );
  42. System.out.println(length(nested));
  43. }
  44. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
3