标签:
#include<stdio.h> int find1(int array[],int length,int value) { if(array==NULL||length==0) return -1; for(int index = 0 ; index < length ; index++) { if(value == array[index]) return index ; } return -1; } int find2(int array[],int length,int value) { if(array==NULL||length==0) return -1; int *start = array; int *end = array + length; while(start<end) { if(value == *start ) return start - array; start++; } return -1; } template<typename type> int find3(type array[],int length,int value) { if(array==NULL||length==0) return -1; type *start = array; type *end = array + length; while(start<end) { if(value == *start ) return start - array; start++; } return -1; } int main(void) { int a[10]={10,11,12,13,14,15,16,17,18,19}; printf("index=%d\n",find1(a,10,14)); printf("index=%d\n",find1(a,0,14)); printf("index=%d\n",find1(a,10,33)); printf("index=%d\n",find2(a,10,15)); printf("index=%d\n",find3<int>(a,10,16)); return 0; }
标签:
原文地址:http://www.cnblogs.com/ycy1025/p/4540060.html