code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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