Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created July 4, 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/71ce1eff105af7442d4d93ad1249dfc9 to your computer and use it in GitHub Desktop.
Save AahanSingh/71ce1eff105af7442d4d93ad1249dfc9 to your computer and use it in GitHub Desktop.
CList insert at the end
func InsertAtEnd(head **Node, x int) {
// Create a new node & make it point to itself.
tmp := &Node{Data: x}
tmp.Next = tmp
fmt.Println("\nInserting", tmp, "at the end")
if *head == nil {
*head = tmp
} else {
p := *head
// Find the last node
for ; p.Next != *head; p = p.Next {
}
p.Next = tmp
// Make the new node point to head
tmp.Next = *head
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment