### BinarySearch and pointers

Hi,

my problem in this program is that I don't know how to use binary search in this code :
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````#include #include using namespace std; int* InsertionSort(int* a, int n) { int x; if (n < 0 || a == NULL) { return NULL; } int* p = new int[n]; if (n == 0) { return p; } p[0] = a[0]; for(int i=0; ij; k--) { p[k] = p[k-1]; x = j; break; } } p[x] = a[i]; } } return p; } int binarySearch(int el, int* a, int n) { int i = 0; int j = 0; while(i <= n) { j = (i + n) / 2; if(a[j] < el) i = j+1; else if(a[j] > el) n = j - 1; else return j; } return -1; } void print(int* a, int n) { for (int i=0; i

Problam is that I have elements in binary search : 42,42,42,42,42,42,42,42,42,114, and dont know how to access to elements : 42,51,71,79...114. I know that pointer always return first element of array but I don't know how to access to other elements in my BinarySort. Thank you for help.
Topic archived. No new replies allowed.