C++之queue和dequeu用法

一、queue介绍与用法 

1.queue.cpp
le Edit Options Buffers Tools C++ Help                                                      
#include                                                                          
#include                                                                             
using namespace std;                                                                        
                                                                                            
int main()                                                                                  
{                                                                                           
  queue myQueue;                                                                       
  //cout << myQueue.empty() << endl;                                                        
  //cout << myQueue.size()<< endl;                                                          
  myQueue.push(1);                                                                          
  myQueue.push(2);                                                                          
  myQueue.push(3);                                                                          
  myQueue.push(4);                                                                          
  myQueue.push(5);                                                                          
  cout <<"First number = "<< myQueue.front()<"<< __LINE__ << " front = " << myQueue.front() << endl;     
  myQueue.pop();                                                                            
  cout <<"xxx----pop twice------>"<< __LINE__ << " front = " << myQueue.front() << endl;    
  cout << myQueue.back()<

二、dequeue介绍与用法 

#include                                               
#include                                                  
using namespace std;                                             
                                                                 
int main()                                                       
{                                                                
  deque myDeque;                                            
  myDeque.push_front(1);                                         
  myDeque.push_front(2);                                         
  myDeque.push_back(3);                                          
  //myDeque.push_back(4);                                        
  //myDeque.push_back(5);                                        
  //myDeque.push_front(6);                                       
  //myDeque.pop_back();                                          
                                                                                                                                  
  deque::iterator myItor;                                   
  for(myItor=myDeque.begin(); myItor!=myDeque.end(); myItor++)   
    cout<<*myItor<
总结:队列先进先出,栈先进后出。
queue容器只能从队尾进行端插入.
dequeue可以访问两端但是只能修改队头,还可以访问两端并且可以在队首和队尾删除和插入元素。

 

你可能感兴趣的:(C++学习)