Skip to content

Instantly share code, notes, and snippets.

@rms1000watt
Created March 10, 2022 05:55
Show Gist options
  • Save rms1000watt/b47b66fc5746768a77ee5478ce78ba55 to your computer and use it in GitHub Desktop.
Save rms1000watt/b47b66fc5746768a77ee5478ce78ba55 to your computer and use it in GitHub Desktop.
just a linked list in go
package main
import "fmt"
type Node struct {
Value string
Next *Node
}
type LinkedList struct {
Current *Node
First *Node
}
func (ll *LinkedList) Insert(Value string) {
if ll.Current == nil {
first := &Node{
Value: Value,
}
ll.Current = first
ll.First = first
return
}
next := &Node{
Value: Value,
}
ll.Current.Next = next
ll.Current = next
}
func (ll *LinkedList) Print() {
curr := ll.First
for {
if curr == nil {
return
}
fmt.Println(curr.Value)
curr = curr.Next
}
}
func main() {
ll := LinkedList{}
ll.Insert("hi1")
ll.Insert("hi3")
ll.Insert("hi2")
ll.Print()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment