SoFunction
Updated on 2025-03-04

Go language implements sequential storage stack

////////
// Sequentially stored stack
////////
package sequence
const MAXSIZE = 20
type Stack struct {
Data [MAXSIZE]int //Storage stack elements
Top int             //Point to the top of the stack, always pointing to the top element, and when empty it is -1
}
//Press up the stack
//d:Stack element
func (s *Stack) Push(d int) bool {
    if +1 > MAXSIZE {
        return false
    }
    [+1] = d
    ++
    return true
}
//Boom stack
func (s *Stack) Pop() int {
    if == -1 {
        return 0
    }
    [] = 0
    d := []
    --
    return d
}
//Stack capacity
func (s *Stack) GetVol() int {
    return len()
}
//Take the length of the stack
func (s *Stack) GetLength() int {
    c := + 1
    return c
}