freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

icpc講義20xx-閱讀頁

2024-09-10 14:12本頁面
  

【正文】 class Pred void sort(greaterT pr)。 }。 請(qǐng)看下面的實(shí)例程序: include iostream include list //include algorithm using namespace std。 int value[]={2,4,5,7,9,12}。l) { int i。 for(pit=()。pit++) cout(*pit) 。 /*ostream_iteratorint output(cout, )。 10 */ } bool sortsp(int v1,int v2) { return v1v2。 (1)。 (4)。 coutThe first list contains: 。 ()。 print(firstl)。 coutThe second list contains: 。 ((),secondl)。 print(firstl)。 coutAfter sort with pare function: 。 ()。 print(firstl)。 coutAfter remove value 9 : 。 ((),value,value+5)。 coutAfter swap with the second list: 。 11 system(PAUSE)。 } 運(yùn)行結(jié)果是: The first list contains: 2 1 4 3 After sort the first list: 1 2 3 4 The second list contains: 2 4 5 7 9 12 After splice the first list contians: 1 2 3 4 2 4 5 7 9 12 After sort with pare function: 12 9 7 5 4 4 3 2 2 1 After unique the first list: 12 9 7 5 4 3 2 1 After remove value 9 : 12 7 5 4 3 2 1 After swap with the second list: 2 4 5 7 9 請(qǐng)按任意鍵繼續(xù) . . . 以上介紹了兩種容器的用法,其他的第一類容器與上面的類似,只是特性和接口函數(shù)上稍微有一些變化,下面將其他容器的接口函數(shù)給出,讀者可自行編制程序來體會(huì)它們的用法。 const_iterator begin() const。 iterator end() const。 size_type size() const。 reference at(size_type pos)。 reference operator[](size_type pos)。 reference front()。 reference back()。 void push_front(const Tamp。 void pop_front()。 x)。 12 iterator insert(iterator it, const Tamp。 void insert(iterator it, size_type n, const Tamp。 void insert(iterator it, const_iterator first, const_iterator last)。 iterator erase(iterator first, iterator last)。 void swap(deque x)。 【 stack 類】 templateclass T, class Cont = dequeT class stack { public: bool empty() const。 value_typeamp。 const value_typeamp。 void push(const value_typeamp。 void pop()。 【 map 類】 map 關(guān)聯(lián)容器用于快速存儲(chǔ)和讀取關(guān)鍵字與相關(guān)值,內(nèi)部是紅黑樹結(jié)構(gòu)。使用的時(shí)候要包含 map頭文件。 const_iterator begin() const。 iterator end() const。 bool empty() const。 key)。 x)。 x)。 iterator erase(iterator it)。 size_type erase(const Keyamp。 13 void clear()。 key_pare key_p() const。 iterator find(const Keyamp。 const_iterator find(const Keyamp。 size_type count(const Keyamp。 iterator lower_bound(const Keyamp。 const_iterator lower_bound(const Keyamp。 iterator upper_bound(const Keyamp。 const_iterator upper_bound(const Keyamp。 pairiterator, iterator equal_range(const Keyamp。 pairconst_iterator, const_iterator equal_range(const Keyamp。 }。 int main() { typedef mapint, double,lessint mid。 (mid::value_type(15,))。 (mid::value_type(15,))。 (mid::value_type(10,))。 (mid::value_type(5,))。 (mid::value_type(15,))。 for(iter=()。iter++) coutiterfirst39。itersecondendl。 pairs[40]=。 for(iter=()。iter++) coutiterfirst\titersecond\tendl。 14 system(PAUSE)。 } 輸出為: 5 10 15 20 25 30 After subscript operations, pairs contains: key value 5 10 15 20 25 30 40 請(qǐng)按任意鍵繼續(xù) . . . 需要注意的是,在使用 map 的查抄 (find)函數(shù)的時(shí)候,如果該關(guān)鍵字沒找到則插入,即如果不 存在的話查找與插入同步完成。 STL 將具有很強(qiáng)通用性的算法如查找、排序、拷貝、反序、替換等許多基本算法寫成通用函數(shù),提供了方便、簡(jiǎn)捷的接口。 Sort templateclass RanIt void sort(RanIt first, RanIt last)。 sort 函數(shù)的第一個(gè)版本是將 operator排序,即由小到大排序。前兩個(gè)參數(shù)是要排序結(jié)構(gòu)的首元素和尾元素的迭代器。 15 int tt[20]。 for(i=0。i++) tt[i]=20i。 for(i=0。i++) couttt[i]“ ”; return 0。由大到小排序: include iostream include vector include algorithm using namespace std。 bool sortspecial(int v1,int v2) { return v1v2。 for(i=0。i++) (i)。 for(i=0。i++) coutgg[i]“ ”; } 要注意的是這個(gè)排序算法是不穩(wěn)定的,即具有相同鍵值的元素的最終位置于開始的相對(duì)位置并不一定相同,例如 7, 7,5,如果按前一個(gè)值排序 則最終兩個(gè) pair 的最終位置無法確定。 同時(shí)在 文件中由一個(gè)快排函數(shù) qsort,原型為: void qsort( void *base, size_t num, size_t width, int (__cdecl *pare )(const void *elem1, const void *elem2 ) )。 int a[9]={1,2,4,5,8,12,23,4,3}。 int main( ) { int i。 /* Output sorted list: */ for(i=0。i++) couta[i] 。 system(PAUSE)。 } int pare( const void *arg1, const void *arg2 ) { return *((int *)arg2)*((int *)arg1)。 templateclass InIt, class T InIt find(InIt first, InIt last, const Tamp。 include algorithm include iostream using namespace std。 int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } 。 // stores the position of the first // matching element. int i 。 // print content of IntArray cout IntArray { 。 i ARRAY_SIZE。 cout } endl 。 //print the matching element if any was found if (location != IntArray + ARRAY_SIZE) // matching element found cout First element that matches value is at location location IntArray endl。 system(PAUSE)。 } Program Output is: IntArray { 1, 2, 3, 4, 4, 5, 6, 7, } First element that matches 4 is at location 3 templateclass InIt, class Pred InIt find_if(InIt first, InIt last, Pred pr)。 // returns true if n is an odd number int IsOdd( int n) { return n % 2 。 int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } 。 // stores the position of the first // element that is an odd number int i 。 for(i = 0。 i++) cout IntArray[i] , 。 // Find the first element in the range [first, last 1 ] 18 // that is an odd number location = find_if(IntArray, IntArray + ARRAY_SIZE, IsOdd) 。 else // no odd numbers in the range cout The sequence does not contain any odd numbers endl
點(diǎn)擊復(fù)制文檔內(nèi)容
試題試卷相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1