Skip to content

Instantly share code, notes, and snippets.

@AahanSingh
Created July 11, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AahanSingh/03c39add7091765d67513278d0e26363 to your computer and use it in GitHub Desktop.
Save AahanSingh/03c39add7091765d67513278d0e26363 to your computer and use it in GitHub Desktop.
DynamicStackPush.go
func (s *Stack) push(x int) {
fmt.Println("\t\t STACK:", *s)
fmt.Println("Pushing", x, "to the stack.")
// If stack is full append the new element. This doubles the capacity of the stack. Then print the new capacity.
if s.isFull() {
(*s).data = append((*s).data, x)
(*s).capacity = cap((*s).data)
(*s).top++
fmt.Println("\tStack Overflow. Increasing stack size to", (*s).capacity)
return
}
(*s).data = append((*s).data, x)
(*s).top++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment