首先可以使用swift定义Stack的结构体

//泛型表达

struct Stack<T> {

  var items = <T>()

  //定义栈顶函数,返回栈顶元素

  mutating func top()->T{

    return items.last!

  }

  //定义push函数,将item插入栈中

  mutating func push(item:T){

    items.append(item)

  }

  //定义pop函数,将栈顶函数退栈

  mutating func pop()->T{

      return items.removeLast()

  }

}