Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created Jul 4, 2021
Embed
What would you like to do?
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