Skip to content

Instantly share code, notes, and snippets.

Created July 4, 2021 05:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AahanSingh/c5d2bff22fd24722aa0bbe16e8ac8cf5 to your computer and use it in GitHub Desktop.
DL List delete last node
func DeleteLast(head **DLNode) {
if *head == nil {
fmt.Println("\nList is empty")
// If there is only 1 node in the list
if (*head).Next == nil {
*head = nil
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