Summary Stack:java V.s. C + +

Source: Internet
Author: User

Summarize the main API operations of the stack.

In C + + and Java, stack operations are almost identical, with only the top element of the query stack having a different name (top () v.s. Peek ()).

In addition, in the constructor, Java uses the class (Character, Integer, String) instead of the primitive type (int, char), which does not have this distinction in C + +.

Java C++ Describe
Structure stack<Integer> mystack = new stack<integer> (); stack<int> mystack; Initialization
Capacity Mystack.empty (); Mystack.empty (); is empty
Capacity Mystack.size (); Mystack.size (); The number of elements in the container
Increase Mystack.push (3); Mystack.push (3); into the stack: inserting an element into the stack (inserted at the top of the stack)
Inquire Mystack. Peek (); Mystack. Top (); Chan: Query stack top element (i.e. the most recently inserted element)
Delete Mystack.pop (); Mystack.pop (); Out stack: Delete top element of stack

Summary Stack:java V.s. C + +

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.