CSC300 / CSC402: Loop using current [5/6] Previous pageContentsNext page

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  public int numUnique() {
    if (first == null) return 0;
    int result = 1;
    Node curr = first.next;
    double prevVal = first.item;
    while (curr != null) {

      double currVal = curr.item;
      if (currVal != prevVal) {
        result += 1;
        prevVal = currVal;
      }
      curr = curr.next;
    }
    return result;
  }

Previous pageContentsNext page