output empty


i did a binarysearch usig c++ but the output is empty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  
#include<iostream>
using namespace std;
int binarysearch(int a[],int maxsize,int target)
{
	int low=0;
	int high=maxsize-1;
	int mid=(low+high)/2;
		while(a[mid]!=target && low<=high)
		{
			if(a[mid]>target)
			{
				high=mid-1;
			}
			else
			{
				low=mid+1;
			}
		}
		if(a[mid]==target)
		{
			return mid;
		}
		else
		{
		return -1;
		}
}
int main()
{
	int j[8]={1,2,3,4,5,6,7,8};
		binarysearch(j,8,5);
}
Last edited on
You should probably be changing mid in your while() loop instead of high and low. And you should probably use the return value instead of discarding it in main().
Last edited on
can you write the code pleasse
No, thank you anyway. You give it a try.

Last edited on
Topic archived. No new replies allowed.