CSC300 / CSC402: Loop using previous [6/6] Previous pageContents

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 prev = first;
    while (prev.next != null) {     
      double prevVal = prev.item;
      double currVal = prev.next.item;
      if (currVal != prevVal) {
        result += 1;

      }
      prev = prev.next;
    }
    return result;
  }

Previous pageContents