[DEV] Completed example

This commit is contained in:
Jian Han 2018-04-14 22:28:24 +10:00
parent 39f2be3c13
commit 5fe2f0aa7f

View File

@ -3,8 +3,8 @@ package main
import "fmt"
type stackEntry struct {
next *stackEntry
value interface{}
Next *stackEntry
Value interface{}
}
type stack struct {
@ -13,8 +13,8 @@ type stack struct {
func (s *stack) Push(v interface{}) {
var e stackEntry
e.value = v
e.next = s.top
e.Value = v
e.Next = s.top
s.top = &e
}
@ -22,15 +22,19 @@ func (s *stack) Pop() interface{} {
if s.top == nil {
return nil
}
v := s.top.value
s.top = s.top.next
v := s.top.Value
s.top = s.top.Next
return v
}
func (s *stack) GetTop() *stackEntry {
return s.top
}
func main() {
s := &stack{}
s.Push("one")
s.Push("two")
s.Push("three")
fmt.Printf("%#v", s)
fmt.Printf("%#v", s.GetTop().Next)
}