Create and Iterate Over Linked List

Run Settings
LanguageGo
Language Version
Run Command
package main import ( "fmt" ) func main() { var list *LinkedList list = &LinkedList{} list.Head = &Node{Value : 4} list.Head.Next = &Node{Value : 2} list.Head.Next.Next = &Node{Value : 3} list.Head.Next.Next.Next = &Node{Value : 1} fmt.Println(list.printValues()) } type Node struct{ Value rune Next *Node } func (n *Node) getNext() *Node{ return n.Next; } type LinkedList struct{ Head *Node } func (list *LinkedList) printValues() string { curr := list.Head str := "" for curr != nil{ str += fmt.Sprintln(curr.Value) curr = curr.Next } return str }
Editor Settings
Theme
Key bindings
Full width
Lines