MCPcopy
hub / github.com/careercup/ctci / main

Method main

java/Chapter 3/Question3_5/Question.java:9–39  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class Question {
9 public static void main(String[] args) {
10 MyQueue<Integer> my_queue = new MyQueue<Integer>();
11
12 // Let's test our code against a "real" queue
13 Queue<Integer> test_queue = new LinkedList<Integer>();
14
15 for (int i = 0; i < 100; i++) {
16 int choice = AssortedMethods.randomIntInRange(0, 10);
17 if (choice <= 5) { // enqueue
18 int element = AssortedMethods.randomIntInRange(1, 10);
19 test_queue.add(element);
20 my_queue.add(element);
21 System.out.println("Enqueued " + element);
22 } else if (test_queue.size() > 0) {
23 int top1 = test_queue.remove();
24 int top2 = my_queue.remove();
25 if (top1 != top2) { // Check for error
26 System.out.println("******* FAILURE - DIFFERENT TOPS: " + top1 + ", " + top2);
27 }
28 System.out.println("Dequeued " + top1);
29 }
30
31 if (test_queue.size() == my_queue.size()) {
32 if (test_queue.size() > 0 && test_queue.peek() != my_queue.peek()) {
33 System.out.println("******* FAILURE - DIFFERENT TOPS: " + test_queue.peek() + ", " + my_queue.peek() + " ******");
34 }
35 } else {
36 System.out.println("******* FAILURE - DIFFERENT SIZES ******");
37 }
38 }
39 }
40}

Callers

nothing calls this directly

Calls 5

randomIntInRangeMethod · 0.95
addMethod · 0.95
sizeMethod · 0.95
removeMethod · 0.95
peekMethod · 0.95

Tested by

no test coverage detected