mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 22:36:05 +03:00
[DEV] Completed example
This commit is contained in:
parent
39f2be3c13
commit
5fe2f0aa7f
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user