Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. public class Stack {
  3.  
  4. private Node head;
  5. public Node next;
  6.  
  7. public Stack() {
  8. head = new Node();
  9. head.data = 0;
  10. }
  11. public Stack( int d ) {
  12. head = new Node();
  13. head.data = d;
  14. }
  15.  
  16. public int pop() {
  17. int temp;
  18.  
  19. temp = head.data;
  20. head = head.next;
  21.  
  22. return temp;
  23. }
  24.  
  25. public void push( int d ) {
  26. Node tmp = new Node();
  27. tmp.data = d;
  28. tmp.next = head;
  29. head = tmp;
  30. }
  31.  
  32. public int peek() {
  33. return head.data;
  34. }
  35.  
  36. //Private Class
  37. private class Node{
  38. int data;
  39. Node next;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement