code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

Traversinglinkedlistrecursively

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

class TraversingLinkedListRecursively {

  static void printlist(Node root) {
    if(root == null){
      return;
    }
    System.out.println(root.data);
    printlist(root.next);
  }

  public static void main(String[] args) {
    Node head = new Node(10);
    head.next = new Node(20);
    head.next.next = new Node(30);
    head.next.next.next = new Node(40);
    printlist(head);
  }
}

Created 2021-12-29T05:57:04+00:00 · Edit