Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Last active July 4, 2021 06:00
Show Gist options
  • Save AahanSingh/87ede898594df65e1718dd822bc4f96c to your computer and use it in GitHub Desktop.
Save AahanSingh/87ede898594df65e1718dd822bc4f96c to your computer and use it in GitHub Desktop.
CList display & find length
func DisplayList(head *Node) {
fmt.Printf("The list is: ")
current := head
if current == nil {
fmt.Println("empty.")
return
} else {
fmt.Print(" -> ", current)
current = current.Next
for ; current != head; current = current.Next {
fmt.Print(" -> ", current)
}
fmt.Println()
fmt.Println()
}
}
func Length(head *Node) int {
current := head
if current == nil {
return 0
} else {
len := 1
current = current.Next
for ; current != head; current = current.Next {
len++
}
return len
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment