import java.util.*;
public class Queue {
private LinkedList list = new LinkedList();
public void queue(Object v) {
list.addFirst(v);
}
public Object dequeue() {
return list.removeLast();
}
public boolean isEmpty() {
return list.isEmpty();
}
public static void main(String[] args) {
Queue queue = new Queue();
int i;
for(i = 0; i < 10; i++)
queue.queue(Integer.toString(i));
while(!queue.isEmpty())
System.out.println(queue.dequeue());
}
}
Queue.java output
0
1
2
3
4
5
6
7
8
9
Tag: Study Code Program Java
No comments:
Post a Comment