-
-
Save AahanSingh/03c39add7091765d67513278d0e26363 to your computer and use it in GitHub Desktop.
DynamicStackPush.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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