File tree 1 file changed +5
-7
lines changed
1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -44,22 +44,20 @@ public E remove(int pos) {
44
44
//catching errors
45
45
throw new IndexOutOfBoundsException ("position cannot be greater than size or negative" );
46
46
}
47
- Node <E > iterator = head .next ;
48
47
//we need to keep track of the element before the element we want to remove we can see why bellow.
49
48
Node <E > before = head ;
50
49
for (int i = 1 ; i <= pos ; i ++) {
51
- iterator = iterator .next ;
52
50
before = before .next ;
53
51
}
54
- E saved = iterator .value ;
52
+ Node <E > destroy = before .next ;
53
+ E saved = destroy .value ;
55
54
// assigning the next reference to the the element following the element we want to remove... the last element will be assigned to the head.
56
- before .next = iterator .next ;
55
+ before .next = before . next .next ;
57
56
// scrubbing
58
- iterator . next = null ;
59
- iterator . value = null ;
57
+ destroy = null ;
58
+ size -- ;
60
59
return saved ;
61
60
62
61
}
63
62
64
63
}
65
-
You can’t perform that action at this time.
0 commit comments