Esempio n. 1
0
 private static void main(String[] args) {
   RandomizedQueue<String> rq = new RandomizedQueue<String>();
   rq.enqueue("hello");
   rq.enqueue(", ");
   rq.enqueue("world");
   rq.enqueue("!");
   System.out.println(rq);
   System.out.printf("size: %d\n", rq.size());
   System.out.printf("sample %s\n", rq.sample());
   System.out.printf("sample %s\n", rq.sample());
   System.out.printf("dequeue %s\n", rq.dequeue());
   System.out.printf("dequeue %s\n", rq.dequeue());
   System.out.println(rq);
   System.out.printf("size: %d\n", rq.size());
 }
  public static void main(String[] args) {
    // unit testing
    RandomizedQueue<String> queue = new RandomizedQueue<String>();
    queue.enqueue("Kabeer");
    queue.enqueue("is");
    queue.enqueue("a");
    queue.enqueue("boy");
    queue.enqueue("dog ");

    String w = queue.dequeue();
    System.out.println("1: " + w);
    System.out.println(queue.size());

    w = queue.dequeue();
    System.out.println("2: " + w);
    System.out.println(queue.size());
    w = queue.dequeue();
    System.out.println("3: " + w);
    System.out.println(queue.size());
    w = queue.dequeue();
    System.out.println("4: " + w);
    System.out.println(queue.size());
    w = queue.dequeue();
    System.out.println("5: " + w);
    System.out.println(queue.size());
    //        for(String x:queue) {
    //            System.out.print(x+" ");
    //        }
    //        System.out.println(" ");
    //
    //
    //        for(String x:queue) {
    //            System.out.print(x+" ");
    //        }
    //
    //        System.out.println(" ");
    //
    //
    //        for(String x:queue) {
    //            System.out.print(x+" ");
    //        }
  }
Esempio n. 3
0
  /**
   * Unit testing
   *
   * @param args the program arguments
   */
  public static void main(String[] args) {
    RandomizedQueue<String> queue = new RandomizedQueue<>();

    queue.enqueue("rieck");
    queue.enqueue("andrew");
    queue.enqueue("thomas");

    assert (queue.size() == 3);
    assert (!queue.isEmpty());

    for (String t : queue) {
      StdOut.println(t);
    }

    queue.sample();

    queue.dequeue();
    queue.dequeue();
    queue.dequeue();

    assert (queue.isEmpty());

    queue.enqueue("lily");
    queue.enqueue("caleb");
    queue.enqueue("aaron");

    assert (queue.size() == 3);
    assert (!queue.isEmpty());

    int i = 0;
    for (String t : queue) {
      StdOut.println(t);
      for (String u : queue) {
        StdOut.println("   " + u);
        i++;
      }
    }

    assert (i == 9);
  }