棧的抽象型別描述(adt):
package org.zp.datastruct;
public inte***ce stack
棧的陣列實現:
package org.zp.datastruct;
// 陣列實現棧
public class arraystack implements stack
public arraystack()
@override
public void clear()
// for(object i:array)
top = 0;
} @override
public boolean isempty()
@override
public object peek()
return array[top - 1];
} @override
public object pop()
object obj = array[--top];
array[top] = null;
return obj;
} @override
public void push(object obj)
array[top ++] = obj; // 只能向棧頂插入資料
} @override
public int size()
private void expand()
array = newarray; }
public string tostring()
buf += array[i];
} buf += " ]";
return buf;
}}
測試類:
package org.zp.datastruct;
public class arraystacktest
}
陣列實現棧
先進後出。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...
棧 Swift陣列實現棧
用陣列實現棧 class stack 棧頂 陣列的最後一條陣列 var peek anyobject?初始化棧,也就是初始化陣列 init 入棧操作 向陣列中追加資料 func push object anyobject 出棧操作 從陣列中移除最後一條資料 func pop anyobject?el...