File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed
Expand file tree Collapse file tree 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) {
4444 //catching errors
4545 throw new IndexOutOfBoundsException ("position cannot be greater than size or negative" );
4646 }
47- Node <E > iterator = head .next ;
4847 //we need to keep track of the element before the element we want to remove we can see why bellow.
4948 Node <E > before = head ;
5049 for (int i = 1 ; i <= pos ; i ++) {
51- iterator = iterator .next ;
5250 before = before .next ;
5351 }
54- E saved = iterator .value ;
52+ Node <E > destroy = before .next ;
53+ E saved = destroy .value ;
5554 // 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 ;
5756 // scrubbing
58- iterator . next = null ;
59- iterator . value = null ;
57+ destroy = null ;
58+ size -- ;
6059 return saved ;
6160
6261 }
6362
6463}
65-
You can’t perform that action at this time.
0 commit comments