国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++隊列用法實例

2020-05-23 14:18:31
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了C++隊列用法,實例分析了C++實現隊列的入隊、出隊、讀取與判斷等相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C++隊列用法。分享給大家供大家參考。具體如下:

 

 
  1. /* 
  2. 隊列使用時必須包含頭文件 #include <queue> 有以下幾種方法 
  3. 入隊push(),出隊pop(), 讀取隊首元素front(),讀取隊尾元素back() , 
  4. 判斷隊是否有元素empty() 
  5. 求隊列元素個數size()  
  6. */ 
  7. #include <iostream> 
  8. #include <queue> 
  9. using namespace std; 
  10. int main() 
  11. queue<int> one; 
  12. one.push(1); 
  13. one.push(2); 
  14. one.push(3); 
  15. cout<<"one 隊列長度:"<<one.size()<<endl; 
  16. cout<<"隊尾元素是:"<<one.back()<<endl; 
  17. cout<<"隊頭元素是:"<<one.front()<<endl;  
  18. cout<<"隊列是否為空(1為空,0為非空):"<<one.empty()<<endl; 
  19. one.pop(); //刪除是從隊頭元素開始的  
  20. cout<<one.front()<<endl; 
  21. cout<<one.size()<<endl; 
  22. //cout<<one.top()<<endl; //普通隊列好像沒有次方法  
  23. //優先隊列的使用 優先隊列中使用back、front 出現錯誤  
  24. priority_queue<int> three; 
  25. three.push(10); 
  26. three.push(20); 
  27. three.push(30); 
  28. cout<<"three 優先隊列長度:"<<three.size()<<endl;  
  29. cout<<"隊列是否為空(1為空,0為非空):"<<three.empty()<<endl; 
  30. while (false == three.empty()) 
  31. cout<<three.top()<<endl; 
  32. three.pop(); 
  33. cout<<endl; 
  34. system("pause"); 
  35. return 0;  

希望本文所述對大家的C++程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 姜堰市| 和政县| 原平市| 深州市| 惠东县| 普格县| 从江县| 中卫市| 师宗县| 吴旗县| 湄潭县| 秀山| 抚远县| 荃湾区| 京山县| 德令哈市| 临高县| 华坪县| 双流县| 崇阳县| 贺州市| 土默特左旗| 吉林省| 遂昌县| 多伦县| 英超| 普兰店市| 合江县| 和平县| 衡山县| 栾川县| 太和县| 龙陵县| 沁水县| 澄江县| 华安县| 合川市| 丽江市| 陇川县| 微博| 彰化县|