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

Method peek

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

Source from the content-addressed store, hash-verified

33 }
34
35 public Animal peek() {
36 if (dogs.size() == 0) {
37 return cats.peek();
38 } else if (cats.size() == 0) {
39 return dogs.peek();
40 }
41 Dog dog = dogs.peek();
42 Cat cat = cats.peek();
43 if (dog.isOlderThan(cat)) {
44 return dog;
45 } else {
46 return cat;
47 }
48 }
49
50 public int size() {
51 return dogs.size() + cats.size();

Callers 3

dequeueAnyMethod · 0.45
peekDogsMethod · 0.45
peekCatsMethod · 0.45

Calls 2

isOlderThanMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected