mchirico / zDaily

Playground to hack and test ideas with Zoe
1 stars 2 forks source link

Day 23: Practice #25

Open mchirico opened 3 years ago

mchirico commented 3 years ago

Create a Go program with 3 or more of the past daily items. Create it quickly, putting down what comes to mind... it doesn't have to make sense...

tacomonkautobot[bot] commented 3 years ago

mchirico, Thanks for opening this issue!

ZoeChiri commented 3 years ago

package main

import "fmt"

type Node struct { prev Node next Node key interface{} }

type List struct { head Node tail Node }

func (L *List) Insert(key interface{}) { list := &Node{ next: L.head, key: key, } if L.head != nil { L.head.prev = list } L.head = list

l := L.head
for l.next != nil {
    l = l.next
}
   L.tail = l

}

func (l *List) Display() { list := l.head for list != nil { fmt.Printf("%+v ->", list.key) list = list.next } fmt.Println() }

func Display(list *Node) { for list != nil { fmt.Printf("%v ->", list.key) list = list.next } fmt.Println() }

func main() { link := List{} link.Insert("Bagels") link.Insert("Salad") link.Insert("Chocolate") link.Insert("Chicken") link.Insert("Broccoli") link.Insert("Cabbage")

fmt.Printf("Grocery List: %v\n", link.head.key)

link.Display()

}