fork(2) 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. class Singlylist{
  9. private ListNode head;
  10. private static class ListNode{
  11. private int data;
  12. private ListNode next;
  13.  
  14. public ListNode(int data){
  15. this.data=data;
  16. this.next=null;
  17. }
  18. }
  19. public void display()
  20. {
  21. ListNode current=head;
  22. while(current!=null)
  23. {
  24. System.out.println(current.data);
  25. current=current.next;
  26. }
  27. //System.out.println("null");
  28. }
  29. public static void main (String[] args)
  30. {
  31. // your code goes here
  32. Singlylist sll=new Singlylist();
  33. sll.head=new ListNode(10);
  34. ListNode sec=new ListNode(34);
  35. ListNode third=new ListNode(34);
  36. ListNode fou=new ListNode(34);
  37. sll.head.next=sec;
  38. sec.next=third;
  39. third.next=fou;
  40. sll.display();
  41. }
  42. }
Success #stdin #stdout 0.08s 46712KB
stdin
Standard input is empty
stdout
10
34
34
34