-
-
Save AahanSingh/a790afcc44b61c88225a1e31223e026b to your computer and use it in GitHub Desktop.
CList insert at start
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 InsertAtStart(head **Node, x int) { | |
// Create new node | |
tmp := &Node{Data: x} | |
tmp.Next = tmp | |
fmt.Println("\nInserting", tmp, "at the start ") | |
if *head == nil { | |
*head = tmp | |
return | |
} | |
p := *head | |
for ; p.Next != *head; p = p.Next { | |
} | |
p.Next = tmp | |
tmp.Next = *head | |
*head = tmp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment