How to search an array using a Sequential Search?

Can someone post a simple example of a Sequential Search searching an array?

I'm trying to use this:
1
2
3
4
5
6
7
8
9
int SequentialSearch(const vector<int> &radicalone, int search)
{
	int i;
	int z;
	for(i=0;i<radicalone.size();i++)
		if(search == radicalone[i])
			z ++;
	return z;
}


It's supposed to return the amount of times a number is in the array, but I don't know what to do in the main function?
Why not use std::count() ?!

Any way:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int SequentialSearch(const std::vector<int> &radicalone, int search)
{
	int i;
	int z = 0;// you should inititalize this
	for(i=0;i<radicalone.size();i++)
		if(search == radicalone[i])
			z ++;
	return z;
}
int main()
{
	std::vector<int> s(2,5);//create a vector containting {5,5} as elements
	std::cout<< SequentialSearch(s,5);

}
Last edited on
I ended up using count. I didn't know about it before. Thanks.

BTW: The Sequential Search does not work at all.
Topic archived. No new replies allowed.