Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created July 4, 2021 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AahanSingh/86f417b8c9c2a76f69481fd32df95694 to your computer and use it in GitHub Desktop.
Save AahanSingh/86f417b8c9c2a76f69481fd32df95694 to your computer and use it in GitHub Desktop.
CList DeleteLast
func DeleteLast(head **Node) {
if *head == nil {
fmt.Println("\nList is empty")
return
}
// Edge Case 1: If there is only 1 node in the list
if (*head).Next == *head {
*head = nil
return
}
current := (*head).Next
previous := *head
for current.Next != *head {
previous = current
current = current.Next
}
fmt.Println("\nDeleting last node: ", current)
previous.Next = *head
current.Next = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment