-
-
Save AahanSingh/2418a0a80f191cabe9e55ab1cc5f01f8 to your computer and use it in GitHub Desktop.
DLList InsertAtStart
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 **DLNode, x int) { | |
// We dont need to explicitly initialize Next & Prev. They will be given the zero value automatically. | |
tmp := &DLNode{Data: x} | |
fmt.Println("\nInserting", tmp, "at the start") | |
if *head == nil { | |
*head = tmp | |
return | |
} | |
tmp.Next = *head | |
(*head).Prev = tmp | |
*head = tmp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment