MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / sample

Method sample

LabEnv/02Lab/RandomizedQueue.java:70–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68
69 // return a random item (but do not remove it)
70 public Item sample() {
71 if (isEmpty()) throw new NoSuchElementException();
72 int id = (first + StdRandom.uniformInt(n)) % v.length;
73 return v[id];
74 }
75
76 // return an independent iterator over items in random order
77 public Iterator<Item> iterator() {

Callers

nothing calls this directly

Calls 1

isEmptyMethod · 0.95

Tested by

no test coverage detected