ArrayBSearch

 
If ArrayBSearch returns 'the nearest element' if it can't find a match, how does one tell if it did or did not find a match?
Another question, if I wanted to remove an element from the middle of an array, could I do this?

int array[10];

//Remove the nth element
int n = 5;
ArrayCopy(array, array, n, n + 1, ArrayRange(array, 0) - n);
ArrayResize(array, ArrayRange(array, 0) - 1);

If I can't do it like this, how could it be done?
 
Make new array, for example,

int array2[9]
ArrayCopy(arrayb, array, 0, 0, n);
ArrayCopy(arrayb, array, n, n + 1, ArrayRange(array, 0) - n);
 
Thanks for that, any takers on the ArrayBSearch question?
I ma be misunderstanding the documentation, but there does not seem to be any way of tell that it succeeded.
 
Well, run this scrypt on any chart:

//+------------------------------------------------------------------+
//|                                            CheckArrayBSearch.mq4 |
//|                                                             Rosh |
//|                    http://www.alpari-idc.ru/ru/experts/articles/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.alpari-idc.ru/ru/experts/articles/"
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int array[10],arrayb[9];
   int n=5,i;
   for (i=0;i<10;i++) array[i]=i;
   ArrayCopy(arrayb, array, 0, 0, n);
   ArrayCopy(arrayb, array, n, n + 1, ArrayRange(array, 0) - n);   
   for (i=0;i<10;i++) 
     {
      Print("i=",i,"  array[",i,"]=",array[i],"  arrayb[",i,"]=",arrayb[i]);
     } 
//----
   return(0);
  }
//+------------------------------------------------------------------+


View Experts Log

2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: removed
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=9 array[9]=9 arrayb[9]=0
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=8 array[8]=8 arrayb[8]=9
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=7 array[7]=7 arrayb[7]=8
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=6 array[6]=6 arrayb[6]=7
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=5 array[5]=5 arrayb[5]=6
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=4 array[4]=4 arrayb[4]=4
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=3 array[3]=3 arrayb[3]=3
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=2 array[2]=2 arrayb[2]=2
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=1 array[1]=1 arrayb[1]=1
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: i=0 array[0]=0 arrayb[0]=0
2007.01.17 20:57:12 CheckArrayBSearch EURUSD,H4: loaded successfully

 
Thank for replying, but there are two parts to the question, the first question is, 'how do we know if ArrayBSearch found the element?'
Do we have to look at the index returned and see if it matches?
 
Sorry,

//+------------------------------------------------------------------+
//|                                            CheckArrayBSearch.mq4 |
//|                                                             Rosh |
//|                    http://www.alpari-idc.ru/ru/experts/articles/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.alpari-idc.ru/ru/experts/articles/"
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int array[10],arrayb[9];
   int n=5,i;
   for (i=0;i<10;i++) array[i]=i;
   ArrayCopy(arrayb, array, 0, 0, n);
   ArrayCopy(arrayb, array, n, n + 1, ArrayRange(array, 0) - n);   
   for (i=0;i<10;i++) 
     {
      Print("i=",i,"  array[",i,"]=",array[i],"  arrayb[",i,"]=",arrayb[i]);
     } 
   Print("ArrayBsearch(arrayb,5,0,0,MODE_ASCEND))=",ArrayBsearch(arrayb,5,0,0,MODE_ASCEND));
   Print("ArrayBsearch(arrayb,5,WHOLE_ARRAY,0,MODE_ASCEND)=",ArrayBsearch(arrayb,5,WHOLE_ARRAY,0,MODE_ASCEND));
   Print("ArrayBsearch(arrayb,5,0,0,MODE_DESCEND))=",ArrayBsearch(arrayb,5,0,0,MODE_DESCEND));
   Print("ArrayBsearch(arrayb,5,WHOLE_ARRAY,0,MODE_DESCEND)=",ArrayBsearch(arrayb,5,WHOLE_ARRAY,0,MODE_DESCEND));
 
//----
   return(0);
  }
//+------------------------------------------------------------------+

Experts Log

2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: removed
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: ArrayBsearch(arrayb, 5,WHOLE_ARRAY, 0,MODE_DESCEND)=0
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: ArrayBsearch(arrayb, 5,0, 0,MODE_DESCEND))=0
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: ArrayBsearch(arrayb, 5,WHOLE_ARRAY, 0,MODE_ASCEND)=4
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: ArrayBsearch(arrayb, 5,0, 0,MODE_ASCEND))=4
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=9 array[9]=9 arrayb[9]=0
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=8 array[8]=8 arrayb[8]=9
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=7 array[7]=7 arrayb[7]=8
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=6 array[6]=6 arrayb[6]=7
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=5 array[5]=5 arrayb[5]=6
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=4 array[4]=4 arrayb[4]=4
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=3 array[3]=3 arrayb[3]=3
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=2 array[2]=2 arrayb[2]=2
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=1 array[1]=1 arrayb[1]=1
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: i=0 array[0]=0 arrayb[0]=0
2007.01.17 21:49:53 CheckArrayBSearch EURUSD,H4: loaded successfully

 
So we do have to check if a match is found? why does not it return -1 or something?

int GetIndex(int& array[], int match)
{
int index = ArrayBSearch(array, match);
if (array[index] == match)
{
return (index);
}
else
{
return (-1);
}
}