kotlin declare variables to remove the question mark (?) Use keyword Lateinit

2023-01-19   ES  

stack implements the data structure that is followed first. The stack is allowed to be inserted (push) and delete (POP) at one end.

In the C ++, use a stack to introduce head files.

#include<stack>

When constructing a stack, it is necessary to specify the storage data type. It can be integer, character type, etc., or it can be a class or other types. For example.

stack<int> s;      // The stack named S is used to store the integer data
stack<double> s2;   // The stack named S2 is used to store dual -precision floating -point data

When there are two types of stacks with the same type, the assignment can be completed with the assignment number.

stack<int> s2;
s2 = s;

can also be constructed.

stack<int> s2(s);

stack can only access the top elements of the stack.

cout << s.top() << endl;

Note: This operation can only return to the top element of the stack, and cannot delete the top element of the stack. To delete the top element, then use itpop()Method.

s.empty();

If the stack is empty, returntrue, otherwise returnfalse

s.size();

Return to the number of elements in the current stack.

s.push(2);

Press 2 into the stack.

s.pop();

Delete the top element of the stack.

Note that this operation can only delete the top element of the stack and cannot return the top element of the stack. If you want to return to the top element of the stack, use ittop()Method.

	stack<int> s;
	s.push(1);
	s.push(2);
	s.push(3);
	
	stack<int> s2;
	s2.push(100);
	s2.push(200);
	s2.push(300);
	
	s.swap(s2);

exchange elements in two stacks.

Use it as follows

Theswapmethod can also achieve the effect of exchange.

swap(s, s2)

More detailed content can be checkeddocumentation

source

Related Posts

[RUST Tiring Notes] Rust basic grammar data type -02

PANDAS summary and calculation description statistics

Commonjs/ES6/AMD module

js Local cache three ways JS local cache

kotlin declare variables to remove the question mark (?) Use keyword Lateinit

Random Posts

Logic Sri Lanka Return (Returning to the chance of numbers) jn

How to build a personal blog website (MAC)

java thread pool?

1 1 1 1 1 1 1 10benben

HDU 1028 IGNATIUS and the Princess III mother function water question, everyone pays attention, I want to start the mother function ~~ lionel