Stack implementation using Java

Source: Internet
Author: User

Stack can be said to be a special linked list. Its main feature is its advanced post-release mechanism, which is an important data structure and is widely used in our programming, for example, polynomial evaluation, balanced input and method call.

ImplementationCodeAs follows:

Package COM. suznhenxing; public class Stack {private int Top =-1; // stack top pointer private object [] items; // Private int size = 0 for data in the stack; private int capacity = 10; Public stack () {items = new object [capacity];} public object POP () {object o = NULL; If (top>-1) {o = items [Top]; size --; top --;} return O;} public void push (Object O) {// If (capacity = size) {capacity * = 2; // resize object [] newitems = new object [capacity]; for (INT I = 0; I <size; I ++) {newitems [I] = items [I];} items = newitems ;} items [top + 1] = O; size ++; top ++;} public int size () {return size ;}}

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.