Main.java

import store.*;

class Main {
   public static void print(STORE str) {
      while (!str.isEmpty()) {
         System.out.println(str.remove());
      };
   }
   public static void main(String[] args) {
      Integer io;
      Stack stack = new Stack();
      Queue queue = new Queue();
      PQueue pqueue = new PQueue(new IntComparer());
      for (int i = 1; i <= 100; i++) {
         io = new Integer(i);
         stack.add(io); queue.add(io); pqueue.add(io);
      };
      Object[] oa = new Object[100];
      for (int i = 200; i >= 101; i--) {
         io = new Integer(i);
         oa[200-i]=io;
      };
      stack.addAll(oa); queue.addAll(oa); pqueue.addAll(oa);
      System.out.println("Stack: "+stack); print(stack);
      System.out.println("Queue: "+queue); print(queue);
      System.out.println("PQueue: "+pqueue); print(pqueue);
   }
}

class IntComparer implements COMPARER {
   public int compare(Object o1, Object o2) {
      int n1 = ((Number)o1).intValue();
      int n2 = ((Number)o2).intValue();

      if (n1<n2) {return 1;};
      if (n1>n2) {return -1;};
      return 0;
   }
}


On to Main1.java Part of MVC Beispiel: ObservableStack
Hubert Baumeister
June 21, 1997

Imprint | Data Protection