@@ -0,0 +1,1985 @@
+package thirty_days_of_code;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement:%0D%0A * You are given a class Node in the editor which has one instance pointer next%0D%0A * pointing to next node and an integer data to store the data in Node.%0D%0A * %0D%0A * You are also given a pointer head pointing to the head node of a linked list%0D%0A * and an integer data to add to the list. Create a new node with the given%0D%0A * integer. Insert this node at the tail of the linked list and return the head%0D%0A * node. The given head pointer may be null, meaning that the initial list is%0D%0A * empty.%0D%0A * %0D%0A * Code for input/output is already handled in the editor. You have to complete%0D%0A * the function insert given in the editor. It takes two arguments: the head%0D%0A * node of the linked list and an integer data to be inserted.%0D%0A * %0D%0A * Input Format: %0D%0A * First line contains T, the number of testcases. Each test case contains an%0D%0A * integer to be inserted at tail of linked list.%0D%0A * %0D%0A * Output Format: %0D%0A * Output the data in each node separated by space.%0D%0A * %0D%0A * Sample Input: %0D%0A * 4%0D%0A * 2%0D%0A * 3%0D%0A * 4%0D%0A * 1%0D%0A * %0D%0A * Sample Output: %0D%0A * 2 3 4 1%0D%0A */%0D%0Apublic class LinkedList %7B%0D%0A%0D%0A%09public static void display(Node head) %7B%0D%0A%09%09Node start = head;%0D%0A%09%09while (start != null) %7B%0D%0A%09%09%09System.out.print(start.data + %22 %22);%0D%0A%09%09%09start = start.next;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public static Node insert(Node head, int data) %7B%0D%0A%09%09Node newNode = new Node(data);%0D%0A%0D%0A%09%09if (head == null) %7B%0D%0A%09%09%09head = newNode;%0D%0A%09%09%09return head;%0D%0A%09%09%7D else %7B%0D%0A%09%09%09Node runner = head;%0D%0A%09%09%09while (runner.next != null) %7B%0D%0A%09%09%09%09runner = runner.next;%0D%0A%09%09%09%7D%0D%0A%09%09%09runner.next = newNode;%0D%0A%09%09%09return head;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public static void main(String args%5B%5D) %7B%0D%0A%09%09Scanner sc = new Scanner(System.in);%0D%0A%09%09Node head = null;%0D%0A%09%09int N = sc.nextInt();%0D%0A%09%09while (N-- %3E 0) %7B%0D%0A%09%09%09int ele = sc.nextInt();%0D%0A%09%09%09head = insert(head, ele);%0D%0A%09%09%7D%0D%0A%09%09display(head);%0D%0A%09%09sc.close();%0D%0A%09%7D%0D%0A%7D%0D%0A%0D%0Aclass Node%7B%0D%0A%09int data;%0D%0A%09Node next;%0D%0A%09Node(int d)%7B%0D%0A        data=d;%0D%0A        next=null;%0D%0A    %7D%0D%0A%7D

Add LinkedList