Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. public abstract class Stack {
  2.  
  3. private int maximalgroesse;
  4. private Object first;
  5.  
  6. public static void main(String[] args) {
  7. Stack st = new Stack(10);
  8. st.push("a");
  9. st.push("b");
  10. st.push("c");
  11. System.out.println(st.pop());
  12. System.out.println(st.pop());
  13. System.out.println(st.pop());
  14. System.out.println(st.isEmpty());
  15.  
  16. }
  17.  
  18. class Object {
  19.  
  20. String value;
  21. Object next;
  22.  
  23. public Object() {
  24. }
  25.  
  26. public Object(String value, Object next) {
  27. this.value = value;
  28. this.next = next;
  29. }
  30.  
  31. public String getValue() {
  32. return this.value;
  33. }
  34.  
  35. public void setValue(String value) {
  36. this.value = value;
  37. }
  38.  
  39. public Object getNext() {
  40. return this.next;
  41. }
  42.  
  43. public void setNext(Object next) {
  44. this.next = next;
  45. }
  46. }
  47.  
  48. public Stack(int maximalgroesse) {
  49. this.maximalgroesse = maximalgroesse;
  50. first = null;
  51. }
  52.  
  53. public void push(Object o) {
  54. o.setNext(first);
  55. first = o;
  56. }
  57.  
  58. public Object pop() {
  59. return first;
  60. }
  61.  
  62. public boolean isEmpty() {
  63. if(first == null) {
  64. return true;
  65. } else {
  66. return false;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement