日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第四讲 deque

發(fā)布時間:2025/6/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第四讲 deque 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

deque ?提供了對首部數(shù)據(jù)進行刪除/插入操作

1 //對一個int型的deque進行首尾添加操作 2 #include "stdafx.h" 3 #include <iostream> 4 5 #include <deque> 6 using namespace std; 7 8 int main() 9 { 10 deque<int> oInt; 11 //0,1,2,3,4 12 for(int i = 0; i < 5; ++i){ 13 oInt.push_back(i); //尾部添加 14 } 15 //4,3,2,1,0,0,1,2,3,4 16 for(int i = 0; i < 5; ++i){ 17 oInt.push_front(i); //首部添加 18 } 19 20 for(int i = 0; i < oInt.size(); ++i){ 21 cout << oInt[i] << endl; 22 } 23 return 0; 24 }

?

對已string型deque進行添加,刪除,查找,插入操作 1 //對已string型deque進行添加,刪除,查找,插入操作 2 #include "stdafx.h" 3 #include <iostream> 4 #include <string> 5 #include <deque> 6 using namespace std; 7 8 int main() 9 { 10 deque<string> oString; 11 //插入數(shù)據(jù)2 3 1 4 12 oString.push_front("2.jiesoon.com"); //首部添加 2位 13 oString.push_back("3.jiesoon.com"); //尾部添加 3 14 oString.push_front("1.jiesoon.com"); //首部添加 1 15 oString.push_back("4.jiesoon.com"); //尾部添加 4 16 // 輸出string是特有的size_type 17 //vector<string>::size_type 是在vector類中typedef的類型 18 for(deque<string>::size_type i = 0; i < oString.size(); ++i){ 19 cout << oString[i] << endl; 20 } 21 cout << "**************************************************" <<endl; 22 //刪除數(shù)據(jù)1 4 23 oString.pop_front(); 24 oString.pop_back(); 25 for(deque<string>::size_type i = 0; i < oString.size(); ++i){ 26 cout << oString[i] << endl; 27 } 28 29 cout << "**************************************************" <<endl; 30 for(deque<string>::iterator itString = oString.begin(); itString != oString.end(); ++itString){ 31 cout << *itString << endl; 32 } 33 34 cout << "**************************************************" <<endl; 35 //查找數(shù)據(jù) 36 deque<string>::iterator itString =find(oString.begin(),oString.end(),"2.jiesoon.com");//find() 37 if(itString != oString.end()){ 38 cout << *itString <<endl; 39 } 40 else{ 41 cout << "can't find 2.jiesoon.com" <<endl; 42 } 43 44 cout << "**************************************************" <<endl; 45 //插入數(shù)據(jù) 46 oString.insert(itString,"1.jiesoon.com"); //insert() 47 for(deque<string>::size_type i = 0; i < oString.size(); ++i){ 48 cout << oString[i] << endl; 49 } 50 51 return 0; 52 }

?

?

?

轉載于:https://www.cnblogs.com/zenseven/p/3808605.html

總結

以上是生活随笔為你收集整理的第四讲 deque的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。