-
-
Save AahanSingh/71ce1eff105af7442d4d93ad1249dfc9 to your computer and use it in GitHub Desktop.
CList insert at the end
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 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