付費(fèi)下載
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
十、set
vico老師set_difference,set_intersection,symmetric_differenceset_union,用于綜合應(yīng)用實例 copyright(C),2015-2020,公司名稱EDU.Co., :Vico Version:2.0 Date2015年08月 :標(biāo)準(zhǔn)類庫中的set操作: :2.0FunctionList:.int_tmain(intargc,_TCHAR*控制臺應(yīng)用程序 2.0 build//StandardLibraryalgorithm#include"stdafx.h"#include<iostream>usingstd::cout;usingstd::cin;using#include<algorithm> //algorithmdefinitions#include<iterator>int_tmain(intargc,_TCHAR*{constintSIZE1=10,SIZE2=5,SIZE3=20;inta1[SIZE1]={1,2,3,4,5,6,7,8,9,10};inta2[SIZE2]={4,5,6,7,8};inta3[SIZE3]={4,5,6,11,15std::ostream_iterator<int>output(cout,"cout<<"a1contains:";std::copy(a1,a1+SIZE1,output);cout<<"\na2contains:";std::copy(a2,a2+SIZE2,output);cout<<"\na3contains:";std::copy(a3,a3+SIZE2,output);//determinewhetherseta2iscompleycontainsedina1if(std::includes(a1,a1+SIZE1,a2,a2+SIZE2))cout<<"\n\na1includesa2.";cout<<"\n\na1doesnotincludesa2.//determinewhetherseta3iscompleycontainedinif(std::includes(a1,a1+SIZE1,a3,a3+SIZE2))cout<<"\na1includesa3.";cout<<"\//deter,omeelementsofa1notinint*ptr=std::set_difference(a1,a1+SIZE1,a2,a2+SIZE2,difference);cout<<"\n\nset_differenceofa1anda2is:";std::copy(difference,ptr,output);int//determineelementsinbotha1andptr=std::set_intersection(a1,a1+SIZE1,a2,a2+SIZE2,cout<<"\n\nset_intersectionofa1anda2is:";std::copy(intersection,ptr,output);intsymmetric_difference[SIZE1+//determineelementsofa1thatarenotina2andelementsofa2thatarenotina1ptr=std::set_symmetric_difference(a1,a1+SIZE1,a3,a3+SIZE2,symmetric_difference);cout<<"\n\nset_symmetric_differenceofa1anda3is:";std::copy(symmetric_difference,ptr,output);int//determineelementsthatareineitherorbothsetsptr=std::set_union(a1,a1+SIZE1,a3,a3+SIZE2,cout<<"\n\nset_unionofa1anda3is:";std::copy(unionSet,ptr,output);cout<<return}運(yùn)行結(jié)十一、lower_bound,upper_bound和 算法中包括函數(shù)有: copyright(C),2015-2020,公司名稱 : :Vico Version:2.0 Date2015年08月 :STL算法: :2.0F_tmain(intargc,_TCHAR*argv[]) 2.0 build//StandardLibraryfunctionslower_bound,upper_boundand//forasortedsequenceofvalues.#include"stdafx.h"#include<iostream>usingstd::cout;usingstd::cin;usingstd::endl;#include<algorithm> //algorithmdefinitions#include<vector> //vectorclass-template#include //int_tmain(intargc,_TCHAR*{constintSIZE=inta1[SIZE]={2,2,4,4,4,6,6,6,6,8std::vector<int>v(a1,a1+SIZE);std::ostream_iterator<int>output(cout,"");cout<<"Vectorvcontains:\n";std::copy(v.begin(),v.end(),output);//determinelower-boundinsertionpointfor6invstd::vector<int>::iteratorlower;lower=std::lower_bound(v.begin(),v.end(),6);cout<<"\n\nLowerboundof6iselement"<<(lower-v.begin())<<"ofvectorv//determineupper-boundinsertionpointfor6invstd::vector<int>::iteratorupper;upper=std::upper_bound(v.begin(),v.end(),6);cout<<"\nUpperboundof6iselement"<<(upper-v.begin())<<"ofvectorv//useequal_rangetodetermineboththelower-andupper-boundinsertionpointsfor6std::vector<int>::iterator>eq;eq=std::equal_range(v.begin(),v.end(),cout<<"\nUsingequal_range:\nLowerboundof6iselement"<<(eq.-v.begin())<<"ofvectorv";cout<<"\nUpperboundof6iselement"<<(eq.second-v.begin())<<"ofvectorvcout<<"\n\nUserlower_boundtolocatethe<<"atwhich5canbeinsertedinorder//determinelower-boundinsertionpointfor5inlower=std::lower_bound(v.begin(),v.end(),5);cout<<"\nLower_boundof5iselement"<<(lower-v.begin())<<"ofvectorvcout<<"\n\nUseUpper_boundtoloatethelastpoint<<"atwhich7canbeinsertedinorder//determineupper-boundinsertionpointfor7invupper=std::upper_bound(v.begin(),v.end(),7);cout<<"\nUpper_boundof7iselement"<<(upper-v.begin())<<"ofvectorvcout<<"\n\nUseequal_rangetolocatetheand<<"lastpointatwhich5canbeinsertedinorder.eq=std::equal_range(v.begin(),v.end(),5);cout<<"\nLowerboundof5iselement<<(eq.-v.begin())<<"ofvectorv";cout<<"\nUpperboundof6iselement"<<(eq.second-v.begin())<<"ofvectorv"<<return}運(yùn)行結(jié)十二、堆排等于這個節(jié)點(diǎn)的值。按照這種方式排序的堆,通常被稱為最大堆(maxheap綜合應(yīng)用實例 copyright(C),2015-2020,公司名稱EDU.Co., :STLPushPopHeapMakeSortheap.cpp :Vico Version:2.0 Date2015年08月 :執(zhí)行堆排序的標(biāo)準(zhǔn)類庫函 :2.0FunctionList:.int_tmain(intargc,_TCHAR*argv[]) 2.0 build//StandardLibraryalgorithmpush_heap,pop_heap,make_heapandsort_heap.#include"stdafx.h"#includeusingstd::cout;usingstd::cin;usingstd::endl;#include<algorithm>#include<vector>#include<iterator>int_tmain(intargc,_TCHAR*{constintSIZE=inta[SIZE]={3,100,52,77,22,31,1,98,13,40 v(a,a+SIZE);std::vector<int>v2;std::ostream_iterator<int>output(cout,"");cout<<"Vectorvbeforemake_heap:";std::copy(v.begin(),v.end(),output);std::make_heap(v.begin(),v.end()); //createheapfromvectorvcout<<"\nVectorvaftermake_heap:std::copy(v.begin(),v.end(),std::sort_heap(v.begin(),v.end()); //sorementswithsort_heapcout<<"\nVectorvaftersort_heap:\n";std::copy(v.begin(),v.end(),output);//performtheheapsortwithpush_heapandpop_heapcout<<"\n\nArrayacontains :";std::copy(a,a+SIZE,output);cout<<endl;//placeelementsofarrayaintov2//maintionelementofv2inheapfor(inti=0;i<SIZE;i++){std::push_heap(v2.begin(),v2.end());cout<<"\nv2afterpush_heap(a["<<i<<"]):";std::copy(v2.begin(),v2.end(),output);}cout<<//removeelementsfromheapinsortedorderfor(unsignedintj=0;j<v2.size();j++){\n}
cout<<"\nv2after"<<v2[0]<<"popped
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 旅行社業(yè)務(wù)操作與規(guī)范手冊
- 航空貨運(yùn)操作流程與管理手冊
- 2025年建筑工程項目施工技術(shù)規(guī)范手冊
- 小升初試卷及答案語文
- 香料分餾工春節(jié)假期安全告知書
- 企業(yè)產(chǎn)品研發(fā)與項目管理規(guī)范
- 建筑工程合同管理與風(fēng)險控制指南
- 2025年倉儲物流安全管理手冊
- 企業(yè)財務(wù)核算與預(yù)算管理指南(標(biāo)準(zhǔn)版)
- 安全生產(chǎn)檔案管理制度
- T/CCPITCSC 120-2023中國品牌影響力評價通則
- 醫(yī)學(xué)檢驗免疫課件
- 農(nóng)村土地永久性轉(zhuǎn)讓合同
- 中建市政道路施工組織設(shè)計方案
- 財務(wù)先進(jìn)個人代表演講稿
- 年度得到 · 沈祖蕓全球教育報告(2024-2025)
- DB23T 2689-2020養(yǎng)老機(jī)構(gòu)院內(nèi)感染預(yù)防控制規(guī)范
- 2025屆天津市和平區(qū)名校高三最后一模語文試題含解析
- 專業(yè)律師服務(wù)合同書樣本
- 建筑施工現(xiàn)場污水處理措施方案
- 學(xué)生計算錯誤原因分析及對策
評論
0/150
提交評論