Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created Jul 4, 2021
Embed
What would you like to do?
DL List delete last node
func DeleteLast(head **DLNode) {
if *head == nil {
fmt.Println("\nList is empty")
return
}
// If there is only 1 node in the list
if (*head).Next == nil {
*head = nil
return
}
current := *head
// Find the last node
for current.Next != nil {
current = current.Next
}
fmt.Println("\nDeleting last node: ", current)
// Change the Next pointer of the penultimate node to nil
current = current.Prev
current.Next = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment