Skip to content

Commit 5720d45

Browse files
Create remove
1 parent ee22cce commit 5720d45

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Doubly Linked Lists/remove

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public Node remove(int index) {
2+
if(index < 0 || index >= length) return null;
3+
if(index == 0) return removeFirst();
4+
if(index == length - 1) return removeLast();
5+
6+
Node temp = get(index);
7+
8+
temp.next.prev = temp.prev;
9+
temp.prev.next = temp.next;
10+
temp.next = null;
11+
temp.prev = null;
12+
13+
length--;
14+
return temp;
15+
}

0 commit comments

Comments
 (0)