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

Method addFirst

02Lab-Queues/Deque.java:45–55  ·  view source on GitHub ↗
(Item item)

Source from the content-addressed store, hash-verified

43
44 // add the item to the front
45 public void addFirst(Item item) {
46 validate(item);
47 Node oldFirst = first;
48 first = new Node();
49 first.item = item;
50 first.prev = null;
51 first.next = oldFirst;
52 if (isEmpty()) last = first;
53 else oldFirst.prev = first;
54 n++;
55 }
56
57 // add the item to the back
58 public void addLast(Item item) {

Callers 1

mainMethod · 0.95

Calls 2

validateMethod · 0.95
isEmptyMethod · 0.95

Tested by

no test coverage detected