-
-
Save AahanSingh/86f417b8c9c2a76f69481fd32df95694 to your computer and use it in GitHub Desktop.
CList DeleteLast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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