JAVA Implementation Stack

Source: Internet
Author: User

JAVA Implementation Stack

Package linklist;/*** JAVA implements the data structure of the stack (Advanced and later) * use arrays to store * @ author zhang **/public class Stack {private Object [] stackElement; private int length = 16; private int size = 0; private int postion = 0; // cursor position public Stack () {} public Stack (int length) {this. length = length;}/*** determines if it is full * @ return */private boolean isFul () {if (postion = size) {return true ;} else {return false ;}}/*** if it is full, apply for a new space and copy the original space to the new space */private void copy () {Object ele [] = new Object [length + 16]; // each amplification of 16 for (int I = 0; I
  
   
= 0 & pos <= postion) {return stackElement [pos];} return null;}/*** traverse all */public void display () {for (int I = postion; I> 0; I --) {Object obj = pop (I); System. out. println (obj. toString () ;}} public static void main (String [] args) {Stack stack Stack = new Stack (); for (int I = 0; I <10; I ++) {stack. push (I);} stack. display ();}}
  

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.