summaryrefslogtreecommitdiffstats
path: root/Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-03-06 12:12:35 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-15 17:38:44 +0100
commitc3f1f5217fd2df4981f427540b2535f566d8a1e8 (patch)
tree9f7870ca6f9c42b07e79dc9a03394ad2669a8aae /Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java
parent73d2d52f4a106ca5467576178c642f351be724b3 (diff)
downloadcoursera-c3f1f5217fd2df4981f427540b2535f566d8a1e8.zip
coursera-c3f1f5217fd2df4981f427540b2535f566d8a1e8.tar.gz
Algorithms-I : 2-Randomized_Queues_Deques: finished
Diffstat (limited to 'Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java')
-rw-r--r--Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java b/Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java
new file mode 100644
index 0000000..61a8502
--- /dev/null
+++ b/Algorithms/Part-I/2-Randomized_Queues_Deques/Subset.java
@@ -0,0 +1,18 @@
+/* vim: set expandtab tabstop=4 shiftwidth=4 : */
+
+public class Subset
+{
+ public static void main(String[] args)
+ {
+ int k = Integer.parseInt(args[0]);
+ if (k == 0) return;
+ RandomizedQueue<String> q = new RandomizedQueue<String>();
+ while (!StdIn.isEmpty())
+ {
+ q.enqueue(StdIn.readString());
+ }
+ for (int i = 0; i < k; i++)
+ System.out.println(q.dequeue());
+ System.out.println();
+ }
+}