File tree 2 files changed +19
-3
lines changed
main/java/com/thealgorithms/datastructures/lists
test/java/com/thealgorithms/datastructures/lists
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,9 @@ public void remove(E e) {
117
117
}
118
118
for (int i = 0 ; i <= layer ; i ++) {
119
119
current .previous (i ).setNext (i , current .next (i ));
120
- current .next (i ).setPrevious (i , current .previous (i ));
120
+ if (current .next (i ) != null ) {
121
+ current .next (i ).setPrevious (i , current .previous (i ));
122
+ }
121
123
}
122
124
size --;
123
125
}
Original file line number Diff line number Diff line change @@ -42,12 +42,26 @@ void contains() {
42
42
}
43
43
44
44
@ Test
45
- void remove () {
45
+ void removeFromHead () {
46
46
SkipList <String > skipList = createSkipList ();
47
+ String mostLeftElement = skipList .get (0 );
47
48
int initialSize = skipList .size ();
48
49
print (skipList );
49
50
50
- skipList .remove ("a" );
51
+ skipList .remove (mostLeftElement );
52
+
53
+ print (skipList );
54
+ assertEquals (initialSize - 1 , skipList .size ());
55
+ }
56
+
57
+ @ Test
58
+ void removeFromTail () {
59
+ SkipList <String > skipList = createSkipList ();
60
+ String mostRightValue = skipList .get (skipList .size () - 1 );
61
+ int initialSize = skipList .size ();
62
+ print (skipList );
63
+
64
+ skipList .remove (mostRightValue );
51
65
52
66
print (skipList );
53
67
assertEquals (initialSize - 1 , skipList .size ());
You can’t perform that action at this time.
0 commit comments