Common data structures and basic usage

 

1:stack(#include<stack>)

size (): returns the number of elements in the stack

top (): Returns the top of the stack elements

pop (): Remove and remove elements from the stack

push (e): e add elements to the stack

empty (): returns true when the stack is empty

{

Handwriting stack

int s [100005] all = 0;
#define push(x) s[++tot]=x
#define pop tot--
#define size tot
#define top s[tot]
 

}

 

2:vector(#include<vector>)

push_back (): at the end of the vector insert elements

Remove elements at the end of the vector: () pop_back

size (): Get the number of elements in a vector

empty (): determines whether the empty vector

clear (): Empty vector element

The vector a = b b copied into a vector

Comparison: holding ==, =,>,> =, <, <= customary meaning;!

Such as: a == b; // a comparative vector and vector b are equal Returns 1

 

3 : (1)queue(#include<queue>)

front (): returns the first element of the queue a reference

back (): Returns the queue in the last reference to the element

push (): Insert an element to the end of the queue

pop (): Remove the first item in the queue

size (): returns the number of elements in queue

empty (): If there are no elements in the queue, then returns true

{

(Handwriting queue)

int s[100005],fnt,end;
#define push(x) s[++end]=x
#define pop fnt++
#define front s[fnt]
#define size end-fnt+1
 

}

 (2)priority_queue

top (): Access the head elements

empty (): whether the queue is empty

size (): returns the number of elements in the queue

push (): the element is inserted into the tail (and ordering)

Customizable {

Default descending;

change:

friend bool operator <(use a,use b){

return a.x>b.x;}

}

 4: and

 deq.size (): the size of the container

max_size (): maximum capacity of the container

deq.resize (): Change the size of the container

empty (): Empty containers sentence

push_front (): Adding the head element

psuh_back (): added to the end elements

pop_front (): Delete the head element

pop_back (): Delete the end of the element

Can be indexed access but the time complexity of large

Guess you like

Origin www.cnblogs.com/zyfltyyz/p/11712919.html