Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class SF5
  2. {
  3. public static void main(String[] args)
  4. {
  5. LL list = new LL();
  6. list.addFirst(1);
  7. System.out.println(list.removeFirst());
  8. }
  9. }
  10. class LL
  11. {
  12. private class Node
  13. {
  14. private Node link;
  15. private int x;
  16. public Node(int x)
  17. {
  18. this.x = x;
  19. }
  20. }
  21. private Node first = null;
  22. private Node last = null;
  23. public void addFirst(int d)
  24. {
  25. Node newNode = new Node(d);
  26. newNode.link = first;
  27. first = newNode;
  28. }
  29. public Node removeFirst()
  30. {
  31. Node p;
  32. p = first;
  33. if (p == null)
  34. return p;
  35. else
  36. {
  37. first = first.link;
  38. return p;
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement