Skip to content

Commit cd5304a

Browse files
committed
Added the Remove Method
1 parent b1dd26d commit cd5304a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

linkedList/LinkedList/LinkedList.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ func (ll *LinkedList) PushFront(val interface{}) *Element {
9898
return e
9999
}
100100

101+
func (ll *LinkedList) Remove(e *Element) * Element {
102+
// if e is the first element of the linkedlist
103+
temp := ll.root.next
104+
if e == temp {
105+
ll.root.next = e.next
106+
ll.len--
107+
} else {
108+
for temp.next != e {
109+
temp = temp.next
110+
}
111+
temp.next = e.next
112+
ll.len--
113+
}
114+
return e
115+
}
116+
101117
func (ll *LinkedList) Print() {
102118
temp := ll.Front()
103119
for temp.next != nil {

0 commit comments

Comments
 (0)