Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Last active June 27, 2021 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AahanSingh/d46386aa1bb5ea364b6f04433c9b411e to your computer and use it in GitHub Desktop.
Save AahanSingh/d46386aa1bb5ea364b6f04433c9b411e to your computer and use it in GitHub Desktop.
Insert a node at the end
func InsertAtEnd(head *Node, x int) *Node {
tmp := Node{Next: nil, Data: x}
current := head
if head == nil {
head = &tmp
} else {
for ; current.Next != nil; current = current.Next {
}
current.Next = &tmp
}
return head
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment