Package algs13

Class MyRandomQueue<T>

java.lang.Object
algs13.MyRandomQueue<T>
All Implemented Interfaces:
Iterable<T>

public class MyRandomQueue<T> extends Object implements Iterable<T>
  • Constructor Details

    • MyRandomQueue

      public MyRandomQueue()
      Create an empty random queue.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Is it empty?
    • size

      public int size()
      Return the number of elements.
    • enqueue

      public void enqueue(T item)
      Add an item.
    • sample

      public T sample()
      Return (but do not remove) a random item.
    • dequeue

      public T dequeue()
      Remove and return a random item.
    • iterator

      public Iterator<T> iterator()
      Return an iterator over the items in random order.
      Specified by:
      iterator in interface Iterable<T>
    • main

      public static void main(String[] args)