Stl use handwriting queue and the queue

A handwritten queue.

 1 struct queue
 2 {
 3     int maxn=10000000;
 4     int first=0,rear=0,a[maxn];
 5     
 6     void push(int x)
 7     {
 8         a[++rear]=x;
 9     }
10     void pop()
11     {
12         first++;
13     }
14     int  front()
15     {
16         return a[first];
17     }
18     int empty()
19     {
20         return first>rear?0:1;
21     }
22 }q;

As shown, my handwriting queue.

Second, the use of ordinary stl queue.

1, the basic operation

. 1  Push (x) 
 2      will be pressed into the end of the queue x
 . 3  
. 4  POP ()     
 . 5      pop the first element of the queue (team top element), note that this function does not return any value
 . 6  
. 7  Front ()
 . 8       returns the first elements (top element team)
 . 9  
10  Back ()
 . 11       return element is pressed into the last (the tail element)
 12 is  
13 is  empty ()
 14       when the queue is empty, return to true
 15  
16  size ()
 . 17       returns the length of the queue

2, using the method

#include <queue>

3, the statement method

    ① general description

     1 queue<int>q; 

    ② structure explained

   

1 struct node
2     {    
3        int x, y;
4     };
5     queue<node>q;

Three, stl priority queue to use

1. Introduction priority queue. Priority Queue not dequeuing enqueued according to the order, but the order of priority in accordance with the size of the elements of the team (or their own operator for calculating ranking)

Meanwhile priority queue (The priority_queue), there are three class parameter template, element type, container type, comparison operator. Vector container is a default, default comparison operator is less, i.e. a small front, after large. I do not understand this a little bit. Anyway, a big priority from the team.

Copy for the original words ( "...... default operator is less, that is, small forward row, the next row is large (the team element of the sequence of the tail team) ......"

2, an exemplary object code defines the following priority queue

. 1 The priority_queue < int > Ql;
 2  
. 3 The priority_queue <pair < int , int >> Q2;
 . 4  
. 5 The priority_queue < int , Vector < int >, Greater < int >> Q3; // small defined first dequeue

3, the operation thereof is substantially the same queue.

4, the application of the word count on the comparison.

Guess you like

Origin www.cnblogs.com/beiyueya/p/12006861.html