Guest User

Untitled

a guest
May 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1.  
  2. class Deque {
  3. // Datenstruktur
  4. int[] store; // zum Speichern von Daten
  5. int current; // aktueller Index
  6.  
  7. // Methoden
  8. Deque(int size) { // Konstruktor
  9. this.store = new int[size];
  10. this.current = -1;
  11. }
  12. boolean isFull() {
  13. return this.current == (this.store.length - 1);
  14. }
  15.  
  16. boolean isEmpty() {
  17. return this.current == -1;
  18. }
  19. void push(double value) {
  20. this.store[++this.current] = (int) value;
  21. }
  22. int pop() {
  23. return this.store[this.current--];
  24. }
  25. double first(){
  26. return this.store[0];
  27. }
  28. double last(){
  29. return this.store[this.store.length-1];
  30. }
  31. double put(){
  32. return this.store[0];
  33. }
  34. double get(){
  35. return this.store[this.store.length-1];
  36. }
  37. }
  38.  
  39.  
  40.  
  41. -------------------------- Neue Datei----------------------------
  42.  
  43.  
  44. class Aufgabe1 {
  45.  
  46. // Testprogramm
  47. public static void main(String[] args) {
  48. int groesse = IO.readInt("Stackgroesse: ");
  49. Deque deque = new Deque(groesse);
  50. //
  51. while (!deque.isFull()) {
  52. deque.push(IO.readDouble("Zahl :"));
  53. }
  54. // Stack leeren
  55. while (!deque.isEmpty()) {
  56. IO.println((double)deque.pop());
  57.  
  58. }
  59.  
  60. IO.println("letzte Zahl(last): "+deque.last());
  61. IO.println("erste Zahl(first): "+deque.first());
  62. IO.println("letzte Zahl(get): "+deque.get());
  63. IO.println("erste Zahl(put): "+deque.put());
  64.  
  65. }
  66. }
Add Comment
Please, Sign In to add comment