can i dynamicaly check the size of an array?

• 11-07-2001
matheo917
can i dynamicaly check the size of an array?
i am currently working on the program that uses recursion...summarizing it ---> have to enter 10 integers into an array and using recursion and and binary search (divide into 2 smaller problems)...
the only thing that gets me stuck is how can I dynamicaly check the size of array as we go deeper and deeper into each recursive call...????? the reason for this is that i need a base (stopper) case that will return a value when an array will have only 1 member...???

i will include the code for this function...
i have commented the problems....

int MaxArray(int Array[], int First, int Last)
{
int Largest;

int Mid = (Array[Last]) / 2; // finding midpoint

if (Last == 1) // won't work..... NOT (Last)
Largest = Array[Last]; // need to have a different base case
// not totally different (just the tiny bit different)

else
{
MaxArray(Array, First, Mid); // One half including midpoint
MaxArray(Array, (Mid + 1), Last); //Second half
// recursive call...
}
// i have to send the results to another function to compare
// integers in term of size......and return the biggest one.

}

i have done the same problem in various easier ways, this time i need to do it this way...

i would appreciate any suggestions and any help...

thanx
• 11-08-2001
zen
Unless you use a sentinel value to mark the end of the array there is no way to dynamically find the size. If you need to to pass on information about the size from the function that created the array, where you can do sizeof(array/array[0]) if necessary, you'll have to send it in separate parameter.
• 11-08-2001
Unregistered
Here are some suggestions:

Don't pass the array about, make it global if you can to reduce stack usage.

Your Mid function should look at the difference between first and last e.g.

Mid = First + (Last - First ) / 2;

Your function should return when the difference between First and Last is <= 1;

Have your function return the maximum of the two values that it is currently checking, this way when your recursion unrolls, the maximum value will float to the top.