Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created July 3, 2021 11:03
Show Gist options
  • Save AahanSingh/2418a0a80f191cabe9e55ab1cc5f01f8 to your computer and use it in GitHub Desktop.
Save AahanSingh/2418a0a80f191cabe9e55ab1cc5f01f8 to your computer and use it in GitHub Desktop.
DLList InsertAtStart
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