-
-
Save AahanSingh/4d4317dc770353203efab8b3754bf739 to your computer and use it in GitHub Desktop.
CList DeleteFirst
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 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