Package Bin;import java.util.arraylist;import Java.util.list;import org.omg.corba.systemexception;/** * @author bin * Target implementation Stack's sequential structure * Abstract: Stack top stack bottom LIFO structure last in first out */public class Bin_stack {private int stacksize;private int Curr ent;private List list;public int getstacksize () {return StackSize;} public void setstacksize (int stackSize) {stackSize = stackSize;} public int GetCurrent () {return to current;} public void Setcurrent (int.) {this.current = current;} Public List getList () {return list;} public void setlist (list list) {this.list = list;} public bin_stack (int size) {this.setlist (New arraylist<> ()); this.setcurrent (0); this.setstacksize (size);} public void push (Object o) {if (this.current = = this. StackSize) {throw new RuntimeException ("full");} Else{list.add (o); current = ++current;}} Public Object POPs () {if (current = = 0) {throw new RuntimeException ("Empty Stack");} Object o = list.get (current-1); List.remove (current-1); current =--current;return o;} public static void Main (string[] args) {Bin_stack B = New Bin_stack (4); B.push (123); B.push (43); System.out.println (B.pop ()); System.out.println (B.pop ()); B.push (4312);}}
The sequential structure of the algorithm stack