//用陣列實現棧
class
stack
//棧頂: 陣列的最後一條陣列
var peek: anyobject?
//初始化棧, 也就是初始化陣列
init()
//入棧操作: 向陣列中追加資料
func push(object
: anyobject)
//出棧操作: 從陣列中移除最後一條資料
func pop() -> anyobject?
else
}}//
建立棧var mystack =stack()
//入棧
mystack.push(object: string(2) as
anyobject)
mystack.push(
object: string(5) as
anyobject)
//出棧
var result =mystack.pop()
print(result!)
//列印棧中的資料
print(mystack.stack)
棧 陣列實現
棧的抽象型別描述 adt package org.zp.datastruct public inte ce stack棧的陣列實現 package org.zp.datastruct 陣列實現棧 public class arraystack implements stack public arra...
陣列實現棧
先進後出。push入棧,pop出棧,peek檢視棧頂元素。陣列實現棧有棧空,棧滿。陣列實現棧package com.st classname stack author gg girl date 2020 9 4 description 棧類。有棧空,棧滿。操作 入棧push,出棧pop,peek檢視...
陣列實現棧
public class stackx public void push long j public long pop public long peek public boolean isempty public boolean isfull public static void main stri...