Linear table-Stack

Source: Internet
Author: User
Package algorithm;/** * Stack * 1. Advanced post-out * 2. The Insert/delete operation can only be inserted at one end of the table. * 3. Traversing data speed is different, first put in the last fetch, traverse the data need to open up temporary space */public class My Stack {private object[] data;private int size;private int top;public mystack () {super (); this.data = new object[10];this.si ze = 0;} public void push (Object o) {data[top++] = o;size++;} Public Object pop () {Size--;return data[--top];} Public Object Peek () {return data[top-1];} public static void Main (string[] args) {mystack s = new Mystack (); S.push (1); S.push (2); S.push (3); System.out.println (S.peek ()); System.out.println (S.pop ()); System.out.println (S.pop ());}}


Linear table-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.