/Users/lyon/j4p/src/bookExamples/ch08ArraysAndVectors/Queues.java
|
1 package bookExamples.ch08ArraysAndVectors;
2
3 import java.util.Vector;
4
5 public class Queues {
6 Vector v = new Vector();
7
8 public void enqueue(Object o) {
9 v.addElement(o);
10 }
11
12 public Object dequeue() {
13 try {
14 return v.remove(0);
15 } catch (java.lang.ArrayIndexOutOfBoundsException e) {
16 return null;
17 }
18 }
19
20 public static void main(String args[]) {
21 Queues q = new Queues();
22 q.enqueue("first");
23 q.enqueue("second");
24 q.enqueue("third");
25 for (Object o = q.dequeue(); o != null; o = q.dequeue())
26 System.out.println(o);
27 }
28 }