首页 > 编程语言 > 详细

C++ STL find

时间:2016-02-05 22:18:03      阅读:186      评论:0      收藏:0      [点我收藏+]

find 函数,复杂度O(n)

涉及一些 泛型编程

 

 1 #include <iostream>
 2 #include <string.h>
 3 #include <string>
 4 
 5 using namespace std;
 6 
 7 template <class iterator, class value>
 8 iterator find(iterator first, iterator last,const T& value)
 9 {
10     while (first != last && *first!= value)
11         ++first;
12     return first;
13 }
14 
15 int main()
16 {
17     int a[1234];
18     for (int i=1;i<=5;i++) a[i]=i;
19     if (find(a+1,a+6,4)) cout<<"hello";
20     return 0;
21 }

 

其中:

template <class iterator, class value>
template <typename iterator, typename value>是一样的

C++ STL find

原文:http://www.cnblogs.com/blankvoid/p/5183621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!