直接上代码
package main
import (
"bufio"
"container/list"
"fmt"
"os"
"strings"
)
//使用list实现一个队列
func main() {
lt := list.New()
consol := bufio.NewScanner(os.Stdin)
for consol.Scan(){
action := consol.Text()
item := strings.Split(action," ")
switch item[0] {
case "push":
if len(item) !=2{
fmt.Println("must be set value")
continue
}
lt.PushBack(item[1])
case "pop":
//val := lt.Front().Value
for ele := lt.Front();ele !=nil;ele = ele.Next(){
fmt.Println(ele.Value)
}
case "quit":
return
default:
fmt.Println("unknown action")
}
}
}