fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. {
  9. Node head;
  10.  
  11. static class Node{
  12.  
  13. int data;
  14. Node next;
  15.  
  16. Node(int d){
  17.  
  18. data=d;
  19. next=null;
  20. }
  21. }
  22.  
  23. public void printList()
  24. {
  25. Node n = head;
  26. while (n != null)
  27. {
  28. System.out.print(n.data+" ");
  29. n = n.next;
  30. }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. public static void main (String[] args) throws java.lang.Exception
  37. {
  38. // your code goes here
  39. LinkedList list =new LinkedList();
  40. list.head =new Node(1);
  41. Node second =new Node(2);
  42. Node third =new Node(3);
  43.  
  44. list.head.next = second;
  45. second.next=third;
  46.  
  47. //System.out.println(list.head);
  48. //System.out.println(list.head.next);
  49. //System.out.println(second.next);
  50. list.printList();
  51.  
  52. }
  53. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
1 2 3