-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubset.java
More file actions
41 lines (34 loc) · 1.08 KB
/
Subset.java
File metadata and controls
41 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package A02RandomizedQueuesAndDeques;
/**
* Created by Adam Gardner and Cesar Gonzalez on 10/8/16.
*/
import edu.princeton.cs.introcs.StdIn;
import edu.princeton.cs.introcs.StdOut;
public class Subset {
public static void main(String[] args){
RandomizedQueue<String> randomQueue = new RandomizedQueue<>();
boolean exit = false;
String string;
StdOut.print("Enter a number: ");
int k = StdIn.readInt();
//read line of Strings
StdOut.println("Enter items to be placed in an array Enter 0 to Exit: ");
while(!exit){
string = StdIn.readString();
if(string.equals("0"))
exit = true;
else
randomQueue.enqueue(string);
}
StdOut.println();
StdOut.print("% echo ");
for(String el: randomQueue){
StdOut.print(el + " ");
}
StdOut.print("| java SubSet " + k);
StdOut.println();
for(int i = 0; i < k; i++){
StdOut.println(randomQueue.dequeue() + " ");
}
}
}