Randomized Queue

From Princeton_Algorithms_I

A randomized queue is similar to a stack or queue, except that the item removed is chosen uniformly at random among items in data structure. Create a generic data type RandomizedQueue that implements the following API:

Performance requirement: Randomized queue must support each randomized queue operation (besides creating an iterator) in constant amortized time. That is, any intermixed sequence of m randomized queue operations (starting from an empty queue) must take cm steps in the worst case, for some constant c. A amortized queue containing n items must use bytes of memory.

Client: Write a client program Permutation.java that takes an integer k as a command line argument; reads a sequence of string from a standard input using Stdin.readString(); and prints exactly k of them, uniformly at random. Print each item from the sequence at most once. you may assume that , where is the number of string on standard input. Note that you are not given .

Solution

Client Program