Well.. you will have to have 2 arrays, and 1 value somewhere or another. I'm assuming you want to pass 1 array, and 1 value, to a function, the function then will assign the values of this temp. array (j) to the values of the passed array (i), unless you are on the element (a) of the value you passed (a), and you are going to assume there are only 10 elements total (i = 0, i < 11).
I dont know what type of arrays these are, so I'm just putting 'int' as the return type. So.. simple fill in the parts you havent done yet:
Code:
int ChangeArray(int array[10], int a)
{
int i=0, j=0;
int new_array[10];
while(i<11) {
if (!(a==i)) {
new_array[j]=array[i];
j++;
}
i++;
}
return new_array[10];
}
You then assign the array (from wherever you are calling this function from) to this function (ie. in main() you have someArray[10], assign someArray[10] = ChangeArray(someArray, 6);.
I would suggest not returning an array unless its necessary, you could have simply passed a pointer to the first element of 'array' and since its a pointer, it would have modified the array from whereever it came from; you would not need to return anything. For example, in the first algorithm you are just removing an element, the one specified in a, well you could go and assign it all to a new array, which could be who knows how big, or you could use a simple booleon to determine when you've found the point you were looking for, and start copying from there, but instead of copying to a new array, you copy to the current array but 1 element up (++i), and it continues to do so from then on (founda = 1):
Code:
void ChangeArray(int *array, int a)
{
int i=0;
bool founda;
while(i<11) {
if (a==i || founda == 1) {
array[i] = array[++i];
founda = 1;
}
}
}
int main()
{
int someArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for(int i = 0; i < 10; ++i)
std::cout << someArray[i];
std::cin.get();
}