Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a client program that utilizes one of the data structures impleme…

…nted in HW2
  • Loading branch information...
commit 65c7cce6acac4ff5409066c856314fe57662ed7f 1 parent de66232
Jakk.Wong@gmail.com authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 HW2/Subset.java
View
22 HW2/Subset.java
@@ -0,0 +1,22 @@
+/* Client program that reads in N strings from standard input and
+ * prints out k number (specified from command-line) of them in a random fashion.
+ *
+ * Execution: echo A B C D E | java Subset 4
+ * Result example - C E B
+ */
+
+public class Subset {
+
+ public static void main(String[] args) {
+ int k = Integer.parseInt(args[0]);
+ // Uses randomized queue as the primary data structure for this program.
+ RandomizedQueue<String> rq = new RandomizedQueue<String>();
+ while(!StdIn.isEmpty()) {
+ rq.enqueue(StdIn.readString());
+ }
+ for (int i = 0; i < k; i ++) {
+ StdOut.println(rq.dequeue());
+ }
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.