fork download
  1. class Node{
  2. int data;
  3. Node next;
  4.  
  5. Node(int data){
  6. this.data=data;
  7. }
  8. }
  9. class linearlinkedlist{
  10. Node first=null;
  11. public void Addfirst(int value){
  12. Node newNode=new Node(value);
  13. newNode.next=first;
  14. first=newNode;
  15. }
  16. public void removefirst(){
  17. Node temp=first;
  18. first=temp.next;
  19. temp.next=null;
  20. }
  21. public void display(){
  22. Node temp=first;
  23. while(temp!=null){
  24. System.out.println(temp.data + "");
  25. temp=temp.next;
  26. }
  27. }
  28. }
  29. class test{
  30. public static void main(String[] args){
  31. linearlinkedlist Ra=new linearlinkedlist();
  32. Ra.Addfirst(20);
  33. Ra.Addfirst(40);
  34. Ra.Addfirst(90);
  35. Ra.removefirst();
  36. Ra.display();
  37.  
  38. }
  39. }
Success #stdin #stdout 0.11s 55332KB
stdin
Standard input is empty
stdout
40
20