The sequential structure of the algorithm stack

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.