Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Deque {
- // Datenstruktur
- int[] store; // zum Speichern von Daten
- int current; // aktueller Index
- // Methoden
- Deque(int size) { // Konstruktor
- this.store = new int[size];
- this.current = -1;
- }
- boolean isFull() {
- return this.current == (this.store.length - 1);
- }
- boolean isEmpty() {
- return this.current == -1;
- }
- void push(double value) {
- this.store[++this.current] = (int) value;
- }
- int pop() {
- return this.store[this.current--];
- }
- double first(){
- return this.store[0];
- }
- double last(){
- return this.store[this.store.length-1];
- }
- double put(){
- return this.store[0];
- }
- double get(){
- return this.store[this.store.length-1];
- }
- }
- -------------------------- Neue Datei----------------------------
- class Aufgabe1 {
- // Testprogramm
- public static void main(String[] args) {
- int groesse = IO.readInt("Stackgroesse: ");
- Deque deque = new Deque(groesse);
- //
- while (!deque.isFull()) {
- deque.push(IO.readDouble("Zahl :"));
- }
- // Stack leeren
- while (!deque.isEmpty()) {
- IO.println((double)deque.pop());
- }
- IO.println("letzte Zahl(last): "+deque.last());
- IO.println("erste Zahl(first): "+deque.first());
- IO.println("letzte Zahl(get): "+deque.get());
- IO.println("erste Zahl(put): "+deque.put());
- }
- }
Add Comment
Please, Sign In to add comment