Simple Linked List of Integer
/* * A simple linked-list of ints. */ package main import "fmt" /* * Node for the linked structure. */ type Node struct { data int next *Node } func main() { // The list. var list *Node // Read integers and build a list. fmt.Println("Enter integers:") for { // Read an integer. var in int num, _ := fmt.Scan(&in) if num != 1 { break } // Make a list node, and add it to the front. newnode := new(Node) newnode.data = in newnode.next = list list = newnode } // Print it out, in reverse order. fmt.Print("Backwards:") scan := list for scan != nil { fmt.Printf(" %d", scan.data) scan = scan.next } fmt.Println() fmt.Println("Thank you for your attention.") }