2 Star 4 Fork 0

lsy/data-structure

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
array_stack.go 680 Bytes
一键复制 编辑 原始数据 按行查看 历史
shouyu.li 提交于 2020-02-21 17:54 +08:00 . 修改包名
package stack
import "gitee.com/kklt1996/data-structure/array"
/*
基于动态数组实现的stack
*/
type ArrayStack struct {
list *array.SliceArray
}
/*
栈是不是空的
*/
func (a ArrayStack) IsEmpty() bool {
return a.list.IsEmpty()
}
/*
~=O(1)
向栈顶添加元素
*/
func (a ArrayStack) Push(element interface{}) {
a.list.AddLast(element)
}
/*
~=O(1)
弹出并获取栈顶的元素
*/
func (a ArrayStack) Pop() (interface{}, error) {
return a.list.RemoveLast()
}
/*
查看栈顶的元素
*/
func (a ArrayStack) Peek() (interface{}, error) {
return a.list.GetLast()
}
/*
获取栈的大小
*/
func (a ArrayStack) GetSize() int {
return a.list.Size()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kklt1996/data-structure.git
git@gitee.com:kklt1996/data-structure.git
kklt1996
data-structure
data-structure
d7c879d1f31d

搜索帮助