assigning nil to pointer

Viewed 5933

I'm trying to implement a delete() method to a list (no HEAD ref)

I find out that I can modify the parameter to a struct.

func (l *LinkedList) Delete(n *Node) {
    if n.next == nil {
        n = nil
    } else {
        current := &n
        *n = *n.next
        *current = nil
    }

}

The "else" part works fine, but deleting the last node does not modify the list

Tried using

*n = nil

But then I have the compile error.

cannot use nil as type Node in assignment

Code complete in this playground:

http://play.golang.org/p/Dhzyd7QHEw

1 Answers
Related