Skip to content

Instantly share code, notes, and snippets.

@mepcotterell
Last active September 3, 2019 16:38
Show Gist options
  • Save mepcotterell/12cfe7afe2f1c223c5bcf6c8fa7c9f5e to your computer and use it in GitHub Desktop.
Save mepcotterell/12cfe7afe2f1c223c5bcf6c8fa7c9f5e to your computer and use it in GitHub Desktop.
package cs1302.example;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.PriorityQueue;
/**
* Interface example app.
* @see https://docs.oracle.com/javase/8/docs/api/java/util/Queue.html
* @see https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html
* @see https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html
*/
public class Driver {
public static void fillQueue(Queue q, int[] nums) {
for (int num : nums) {
q.add(num);
} // for
} // fillQueue
public static void processQueue(Queue q) {
System.out.println("processing queue:");
while (!q.isEmpty()) {
System.out.print("handling ticket ");
System.out.println(q.poll());
} // while
} // processQueue
public static void main(String[] args) {
int nums[] = new int[] { 9, 1, 3, 2, 7 };
Queue q1 = new ArrayDeque(); // boss says first-come-first-serve is okay
fillQueue(q1, nums);
Queue q2 = new PriorityQueue(); // boss says we must handle according to priority
fillQueue(q2, nums);
processQueue(q1);
processQueue(q2);
} // main
} // Driver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment