一、vector容器四種遍歷方式
二、vector容器建立三維陣列#include#include #include using namespace std;
void print(vector v);
bool mycmpare(const int &a, const int &b)
// 定義三個結構體
struct cvector2;};
struct cvector3;};
struct obj
;int main()
// 遍歷方式 2,採用迭代器,並採用c++11新標準中的auto關鍵字
cout << "遍歷方式 2,採用迭代器,並採用c++11新標準中的auto關鍵字 " << endl;
for (auto it = object.texcoord.begin(); it != object.texcoord.end(); it++)
// 遍歷方式 3,採用下角標進行資料元素訪問
cout << "遍歷方式 3,採用下角標進行資料元素訪問" << endl;
for (size_t i = 0; i < object.texcoord.size(); i++)
//遍歷方式 4,採用c++11新標準中的auto關鍵字
cout << "遍歷方式4,採用c++11新標準中的auto關鍵字" << endl;
for (auto i : object.texcoord)
/*vector的使用
*/ /*
vectorv1;
print(v1);
vectorv2(5);
print(v2);
vectorv3(5, 1);
print(v3);
v3.insert(v3.begin(), 3);
print(v3);
*/ system("pause");
}void print(vectorv)
/*vector::iterator it;
for (it = v.begin(); it != v.end(); it++)
*/}
#include#include#include #include using namespace std;
int main()
} }// 輸出三維陣列
for (int z = 0; z < highnum; z++)
cout << endl;
} cout << endl;
} // 計算三維陣列的行、列、高
vector> temp;
temp = vect[0]; //y,z平面賦值給test
cout << "linenum: " << vect.size() << endl;
cout << "rownum: " << temp.size() << endl;
cout << "highnum: " << vect[0][0].size() << endl;
system("pause");
}
c vector容器的巢狀使用
目錄 1 定義 2 新增元素 3 訪問元素 4 長度 vectorint m 這裡是vector的巢狀使用,本質是vector元素裡的每個元素也是vector型別,所以抓住本質來新增元素就比較容易理解。我們假設外層的vector的物件為m,為外層vector物件,則m中的每乙個元素也是vector型...
C set容器使用
stl的set是乙個二叉排序樹,也稱為集合,其在stl內部實現是紅黑樹,能夠將元素預設從小到大排序或者是字典序排序。如果宣告的元素型別不是基本資料型別而是自定義的類要給它乙個比較器,類似於sort的compare。include include include include using names...
C set 容器使用
g set.cc std c 17 set 容器使用 set 內部是使用紅黑樹實現的,是一種平衡二叉樹,所以對其插入 查詢效率是非常高的,其時間複雜度是log2 n set是stl中一種標準關聯容器。它底層使用平衡的搜尋樹 紅黑樹實現,插入刪除操作時僅僅需要指標操作節點即可完成,不涉及到記憶體移動和...