mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
952 B
56 lines
952 B
1 year ago
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func PrintList(l *List) {
|
||
|
it := l.Head
|
||
|
for it != nil {
|
||
|
fmt.Print(it.Data, " -> ")
|
||
|
it = it.Next
|
||
|
}
|
||
|
|
||
|
fmt.Print(nil, "\n")
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
link := &List{}
|
||
|
link2 := &List{}
|
||
|
|
||
|
fmt.Println("----normal state----")
|
||
|
ListPushBack(link2, 1)
|
||
|
PrintList(link2)
|
||
|
ListRemoveIf(link2, 1)
|
||
|
fmt.Println("------answer-----")
|
||
|
PrintList(link2)
|
||
|
fmt.Println()
|
||
|
|
||
|
fmt.Println("----normal state----")
|
||
|
ListPushBack(link, 1)
|
||
|
ListPushBack(link, "Hello")
|
||
|
ListPushBack(link, 1)
|
||
|
ListPushBack(link, "There")
|
||
|
ListPushBack(link, 1)
|
||
|
ListPushBack(link, 1)
|
||
|
ListPushBack(link, "How")
|
||
|
ListPushBack(link, 1)
|
||
|
ListPushBack(link, "are")
|
||
|
ListPushBack(link, "you")
|
||
|
ListPushBack(link, 1)
|
||
|
PrintList(link)
|
||
|
|
||
|
ListRemoveIf(link, 1)
|
||
|
fmt.Println("------answer-----")
|
||
|
PrintList(link)
|
||
|
}
|
||
|
|
||
|
func ListPushBack(l *List, data interface{}) {
|
||
|
n := &NodeL{Data: data}
|
||
|
if l.Head == nil {
|
||
|
l.Head = n
|
||
|
l.Tail = n
|
||
|
} else {
|
||
|
l.Tail.Next = n
|
||
|
l.Tail = n
|
||
|
}
|
||
|
}
|