コード例 #1
0
func problem1() {
	fmt.Printf("Problem 2.1\n")
	dashes := strings.Repeat("-", 50)
	fmt.Println(dashes)
	mfList := new(list.DoublyLinkedList)
	mfList.Push(list.Person{Name: "Kengo", Age: 27})
	mfList.Push(list.Person{Name: "Ichikawa", Age: 33})
	mfList.Push(list.Person{Name: "Asano", Age: 35})
	mfList.Push(list.Person{Name: "Kengo", Age: 27})
	fmt.Println(dashes)
}
コード例 #2
0
func doublyLinkedListTest() {
	dashes := strings.Repeat("-", 50)

	mfList := new(list.DoublyLinkedList)
	mfList.Push(list.Person{Name: "Kengo", Age: 27})
	mfList.Push(list.Person{Name: "Ichikawa", Age: 33})
	mfList.Push(list.Person{Name: "Asano", Age: 35})

	processed := make(map[*list.Node]bool)

	fmt.Println("First time through list...")
	for n := mfList.First(); n != nil; n = n.Next() {
		fmt.Printf("%s\n", n.Name)
		if processed[n] {
			fmt.Printf("%s as been processed\n", n.Name)
		}
		processed[n] = true
	}

	fmt.Println(dashes)
	fmt.Println("Second time through list...")
	for n := mfList.First(); n != nil; n = n.Next() {
		fmt.Printf("%v", n.Name)
		if processed[n] {
			fmt.Println(" has benn processed")
		} else {
			fmt.Println()
		}
		processed[n] = true
	}

	fmt.Println(dashes)
	// var found_node *Node
	name_to_find := "Kengo"
	mfList.Find(name_to_find)
	// Not in the List
	name_to_find = "Tsuji"
	mfList.Find(name_to_find)

	fmt.Println(dashes)
	name_to_remove := "Kengo"
	mfList.Delete(name_to_remove)
	mfList.Delete(name_to_remove)

	fmt.Println(dashes)
	fmt.Println("*Pop each value in the list...")
	for person, err := mfList.Pop(); err == nil; person, err = mfList.Pop() {
		fmt.Printf("%v\n", person)
	}
	//fmt.Println(mfList.Pop())

}