Golang 数据结构之【4.4顺序栈】
由于 进栈和出栈没有涉及任何循环语句,因此时间复杂度均是 0(1) golang代码实现如下: package main //顺序栈 import ( "errors" "fmt" ) const MaxSize = 20 //存储空间初始分配量 type SElemType int // SElemType类型根据实际情况而定,这里假设为int type SqStack struct { data [MaxSize]SElemType //栈的数据容量,用数组实现。如果不确定最大值可以用slice类型,这里我选择用数组。 top int //栈顶指针 } // 初始化一个空栈 func (s *SqStack) InitStack () { s.top = -1 } // 把s置为空栈 f...阅读全文