Subversion Repositories programming

Rev

Rev 100 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
24 irasnyd 1
//Written by Ira Snyder
2
//11-03-2004
108 ira 3
// License: Public Domain (added 07-11-2005)
24 irasnyd 4
 
5
import java.util.LinkedList;
6
 
7
class Queue {
26 irasnyd 8
    private LinkedList list;
24 irasnyd 9
 
26 irasnyd 10
    public Queue( ) { list = new LinkedList(); } //create an empty queue
11
 
12
    //put the item at the back of the queue
13
    public void enqueue( Object o ) { 
14
        if( list.isEmpty() ) { list.add(o); }
15
        else { list.addLast(o); } 
16
    }
17
 
18
    //remove the item from the front of the queue
19
    public Object dequeue() { return list.removeFirst(); }
24 irasnyd 20
 
26 irasnyd 21
    //check if the queue is empty
22
    public boolean isEmpty() { return list.isEmpty(); }
24 irasnyd 23
}
24