理论介绍
   
栈(stack),是计算机科学中一种特殊的串列形式的抽象数据类型,其也通常使用链表或者数据来实现, 与队列不用,栈的性质是后进先出。也就是只能总栈的顶部插入元素与取出元素。
    性质:
    
    后进先出
   
    代码实现
   
package stack
type Item interface {
}
// ItemStack the stack of items
type ItemStack struct {
    items []Item
}
// New Create a new ItemStack
func (s *ItemStack) New() *ItemStack {
    s.items = []Item{}
    return s
}
// Push adds an Item to the top of the stack
func (s *ItemStack) Push(t Item) {
    s.items = append(s.items, t)
}
// Pop removes an Item from the top of the stack
func (s *ItemStack) Pop() *Item  
版权声明:本文为afar_ch原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
