⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 搜索算法.cpp

📁 c c++利用c++写得比较常用的收索算法
💻 CPP
字号:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc,char *argv[])
{
	int elems[] = { 5,6,9,8,8,3};
	vector<int> myVector(elems,elems+6);
	vector<int>::const_iterator it,it2;
	
	it = min_element(myVector.begin(),myVector.end());
	it2 = max_element(myVector.begin(),myVector.end());
	cout<<"The min is "<<*it<<" and the max is "<<*it2<<endl;
	it = adjacent_find(myVector.begin(),myVector.end());
	if(it != myVector.end()){
		cout<<"Found two consecutive equal elements of value "
		<<*it<<endl;
	}
	int targets[] = {8,9};
	it = find_first_of(myVector.begin(),myVector.end(),targets,targets+2);
	if(it != myVector.end()){
          cout<<"Found one of 8 or 9: "<<*it<<endl;
    }
    int sub[] = {8,3};
    it = search(myVector.begin(),myVector.end(),sub,sub+2);
	if(it != myVector.end()){
		cout<<"Found subsequence 8,3 at position "<<it - myVector.begin()<<endl;
	}
	it2 = find_end(myVector.begin(),myVector.end(),sub,sub+2);
	if(it != it2){
		cout<<"Error: search and find_end found different subsequences "
		<<" even though threre is only one match.\n";
	}
	it = search_n(myVector.begin(),myVector.end(),2,8);
	if(it != myVector.end()){
		cout<<"Found two consecutive 8s starting at position "
		<<it - myVector.begin()<<endl;
	}
	getchar();
	return 0;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -