Created
September 30, 2011 20:49
-
-
Save silveira/1254938 to your computer and use it in GitHub Desktop.
PriorityQueue order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Example { | |
public static void main(String[] args) { | |
Queue<String> q = new PriorityQueue<String>(); | |
q.offer("carrot"); | |
q.offer("apple"); | |
q.offer("banana"); | |
for(String fruit: q) | |
System.out.println(fruit); | |
/* | |
apple | |
carrot | |
banana | |
*/ | |
System.out.println(); | |
while(q.isEmpty()==false) | |
System.out.println(q.poll()); | |
/* | |
apple | |
banana | |
carrot | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment