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 + +