Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Following implemetation of Stack tie each element to it parent
- type stackElement struct {
- data interface{}
- next *stackElement
- }
- type Stack struct {
- Size int32
- head *stackElement
- }
- func (stack *Stack) Push(data interface{}) {
- element := new(stackElement)
- element.data = data
- element.next = stack.head
- stack.head = element
- stack.Size++
- }
- func (stack *Stack) Pop() interface{} {
- if stack.head == nil {
- return nil
- }
- v := stack.head.data
- stack.head = stack.head.next
- stack.Size--
- return v
- }
- func (stack *Stack) IsEmpty() bool {
- return stack.head == nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement