Download the following class into your java program directory: CharQueue.class. Then copy/paste the following program and compile and run it:

//the program demonstrates a queue used to store characters
public class ShowQueue {
	public static void main(String [] args) {
	    // creating a new queue
		CharQueue cq = new CharQueue();
		// a variable to store stack characters
		char c;

		cq.enqueue('a');
		cq.enqueue('b');
		c = cq.dequeue();
		System.out.println("c = " + c);
		cq.enqueue('c');
		cq.enqueue('d');

		while( !cq.isEmpty()) {
		    c = cq.dequeue();
		    System.out.print(c);
		}
		System.out.println(); // new line
	}
}

This is an example from CSci 2101 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.