This is a basic sequential search of a randomly generated array. I keep getting errors on it. I want to get this working, then I will change the search to make it recursive for my actual assignment... one step at a time. I'm having quite a lot of problems with the class lately especially when it comes to templates. Any help would be much appreciated. If I've failed to give you any information please let me know. I'm not using a header file since the program is very simplistic... I'm sure I'm missing something very small and silly.. at least I hope I am.
#include <cstdlib>
#include <iostream>
using namespace std;
template <class elemType>
int seqSearch(const elemType list[], int length, const elemType& item);
int main(int argc, char *argv[])
{
srand(time(NULL));
int length = 50;
int i = 0;
int list[length];
int item = 25;
//POPULATES THE ARRAY WITH RANDOM NUMBERS
for(i = 0; i < length; i++)
list[i] = rand() %100 +1;
//SEARCHES THE ARRAY
seqSearch(list[], length, item);
system("PAUSE");
return EXIT_SUCCESS;
}
template <class elemType>
int seqSearch(const elemType list[], int length, const elemType& item){
int loc;
bool found = false;
loc = 0;
while (loc < length && !found)
if (list[loc] == item)
found = true;
else
loc++;
if (found)
return loc;
else
return -1;
}
I can't get it to compile. It gives me the error on line 24 - Expected primary-expression before ']' token