Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created Jul 4, 2021
Embed
What would you like to do?
CList DeleteFirst
func DeleteFirst(head **Node) {
if *head == nil {
fmt.Println("\nList empty")
return
}
fmt.Println("\nDeleting first Node: ", *head)
// Edge Case 1: Only one node exists in the list
if (*head).Next == *head {
*head = nil
return
}
// Traverse to last node
p := *head
for ; p.Next != *head; p = p.Next {
}
p.Next = (*head).Next
*head = (*head).Next
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment