 |
|

What will the following program output?
// Prototypes
void DoSomething(int arr[], int target, int &arrLength);
void DoSomething2(int arr[], int current, int target, int &arrLength);
void DoSomething3(int arr[], int target, int &arrLength);
// Function implementation
void DoSomething(int arr[], int target, int &arrLength)
{
int i=0;
DoSomething2(arr, i, target, arrLength);
}
void DoSomething2(int arr[], int current, int target, int &arrLength)
{
if (current == arrLength) return;
if (arr[current] == target) {
DoSomething3(arr, current, arrLength);
arrLength--;
}
else {
DoSomething2(arr, current+1, target, arrLength);
}
}
void DoSomething3(int arr[], int current, int &arrLength)
{
if (current>=arrLength-1) return;
arr[current] = arr[current+1];
DoSomething3(arr, current+1, arrLength);
}
int main()
{
int arr[] = {15, 3, 21, 7, 55};
int arrLength = 5;
DoSomething(arr, 3, arrLength);
for (int i=0; i< arrLength; i++) {
cout << arr[i] << ", ";
}
cout << endl;
return 0;
}
|
 |
| |
|
|
 |