MCPcopy Create free account
hub / github.com/careercup/ctci / dequeueAny

Method dequeueAny

java/Chapter 3/Question3_7/AnimalQueue.java:20–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18 }
19
20 public Animal dequeueAny() {
21 if (dogs.size() == 0) {
22 return dequeueCats();
23 } else if (cats.size() == 0) {
24 return dequeueDogs();
25 }
26 Dog dog = dogs.peek();
27 Cat cat = cats.peek();
28 if (dog.isOlderThan(cat)) {
29 return dogs.poll();
30 } else {
31 return cats.poll();
32 }
33 }
34
35 public Animal peek() {
36 if (dogs.size() == 0) {

Callers 1

mainMethod · 0.95

Calls 5

dequeueCatsMethod · 0.95
dequeueDogsMethod · 0.95
isOlderThanMethod · 0.80
sizeMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected