From d3936993d3b1a552e278e13791c6d5c2276a1031 Mon Sep 17 00:00:00 2001 From: ofrezuufghkbdfejv Date: Mon, 18 Dec 2023 17:18:26 +0100 Subject: [PATCH] stack + queue --- Stack.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Stack.java diff --git a/Stack.java b/Stack.java new file mode 100644 index 0000000..f15db93 --- /dev/null +++ b/Stack.java @@ -0,0 +1,52 @@ + +/** + * Beschreiben Sie hier die Klasse List_T_. + * + * @author (Ihr Name) + * @version (eine Versionsnummer oder ein Datum) + */ +public class Stack +{ + private Node first; + + public Stack() { + first = null; + } + + public boolean isEmpty() { + if (first == null) return true; + return false; + } + + + public T top(int n) { + if (first == null) return null; + return first.wert; + } + + public void push(T val) { + Node neu = new Node (); + neu.wert = val; + neu.next = first; + + first = neu; + } + + + public T pop(int n) { + if (first == null) return null; + T tmp = first.wert; // wert von first (=0) speichern + first = first.next; //first "pfeil" auf den nächsten + return tmp;//wert ausgeben + } + + public String toString(){ // glaub um halt alles schön auszugeben + String result = ""; + Node current = first; + while (current != null){ + result += current.wert + ", "; + current = current.next; + } + return result; + } + }