Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Stack {
- private int maximalgroesse;
- private Object first;
- public static void main(String[] args) {
- Stack st = new Stack(10);
- st.push("a");
- st.push("b");
- st.push("c");
- System.out.println(st.pop());
- System.out.println(st.pop());
- System.out.println(st.pop());
- System.out.println(st.isEmpty());
- }
- class Object {
- String value;
- Object next;
- public Object() {
- }
- public Object(String value, Object next) {
- this.value = value;
- this.next = next;
- }
- public String getValue() {
- return this.value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- public Object getNext() {
- return this.next;
- }
- public void setNext(Object next) {
- this.next = next;
- }
- }
- public Stack(int maximalgroesse) {
- this.maximalgroesse = maximalgroesse;
- first = null;
- }
- public void push(Object o) {
- o.setNext(first);
- first = o;
- }
- public Object pop() {
- return first;
- }
- public boolean isEmpty() {
- if(first == null) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement