SHARE
TWEET

Untitled

a guest Apr 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Following implemetation of Stack tie each element to it parent
  2. type stackElement struct {
  3.     data interface{}
  4.  
  5.     next *stackElement
  6. }
  7.  
  8. type Stack struct {
  9.     Size int32
  10.     head *stackElement
  11. }
  12.  
  13. func (stack *Stack) Push(data interface{}) {
  14.     element := new(stackElement)
  15.     element.data = data
  16.     element.next = stack.head
  17.     stack.head = element
  18.     stack.Size++
  19. }
  20.  
  21. func (stack *Stack) Pop() interface{} {
  22.     if stack.head == nil {
  23.         return nil
  24.     }
  25.  
  26.     v := stack.head.data
  27.     stack.head  = stack.head.next
  28.     stack.Size--
  29.  
  30.     return v
  31. }
  32.  
  33. func (stack *Stack) IsEmpty() bool {
  34.     return stack.head == nil
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top