#include #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { //1.容器Container有兩種: //(1)Sequential Container序列容器:Vector,List,deque // *使用 index // 優點:方便新增,刪除item //(2)Associative Container 關聯容器:Set, Map, // *使用 key-value paris // 優點:方便搜尋 //2.Vector = 動態陣列,很像array,但可以push back動態在最後尾部新增,刪除資料 //優點:適合在『尾部』新增,刪除一筆資料 //缺點:在『頭部,中間』新增,刪除資料比較沒有效率(修改一個,其它後面的都要修正index) //缺點:搜尋資料是逐筆比對,效率差 //3.List = 是很多獨立的記憶體空間(空間內有2個值,data,index), //特色:靠index指向另一個記憶體空間,所以list是一種雙向鏈表串接 //優點:適合在『頭部,中間,尾部』的新增,刪除效率 // insert一筆資料,只要修正兩個空間的鏈接index即可,其它都不要修正 //缺點:搜尋資料要逐筆比對,而且還要把記憶體空間值抓到cache,所以搜尋效率最差 // 4.宣告a1是vector動態陣列 vector a1; //5.加入item: push_back a1.push_back(90); a1.push_back(85); a1.push_back(95); a1.push_back(100); a1.push_back(70); //6.顯示全部vector //length = a1.size() //顯示全部方法1: a1[i] for(int i=0;i