mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
update book code
This commit is contained in:
45
eBook/exercises/chapter_10/main_stack.go
Executable file
45
eBook/exercises/chapter_10/main_stack.go
Executable file
@@ -0,0 +1,45 @@
|
||||
// Q15.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"./stack/stack"
|
||||
)
|
||||
|
||||
func main() {
|
||||
st1 := new(stack.Stack)
|
||||
fmt.Printf("%v\n", st1)
|
||||
st1.Push(3)
|
||||
fmt.Printf("%v\n", st1)
|
||||
st1.Push(7)
|
||||
fmt.Printf("%v\n", st1)
|
||||
st1.Push(10)
|
||||
fmt.Printf("%v\n", st1)
|
||||
st1.Push(99)
|
||||
fmt.Printf("%v\n", st1)
|
||||
p := st1.Pop()
|
||||
fmt.Printf("Popped %d\n", p)
|
||||
fmt.Printf("%v\n", st1)
|
||||
p = st1.Pop()
|
||||
fmt.Printf("Popped %d\n", p)
|
||||
fmt.Printf("%v\n", st1)
|
||||
p = st1.Pop()
|
||||
fmt.Printf("Popped %d\n", p)
|
||||
fmt.Printf("%v\n", st1)
|
||||
p = st1.Pop()
|
||||
fmt.Printf("Popped %d\n", p)
|
||||
fmt.Printf("%v\n", st1)
|
||||
}
|
||||
/* Output:
|
||||
[0:3]
|
||||
[0:3] [1:7]
|
||||
[0:3] [1:7] [2:10]
|
||||
[0:3] [1:7] [2:10] [3:99]
|
||||
Popped 99
|
||||
[0:3] [1:7] [2:10]
|
||||
Popped 10
|
||||
[0:3] [1:7]
|
||||
Popped 7
|
||||
[0:3]
|
||||
Popped 3
|
||||
*/
|
Reference in New Issue
Block a user