{ int main()
int mrg_sort(int arr1[], int n1, int arr2[], int n2, int result[])
{
int i, j, k;
i = j = k = 0;
while (i< n1 && j<n2){
if (arr1[i] < arr2[j])
result[k++] = arr1[i++];
elseif(arr1[i] > arr2[j])
result[k++] = arr2[j++];
else{
result[k++] = arr1[i++];
j++;
}
}
if (i<n1){
while (i<n1)
result[k++] = arr1[i++];
}
elseif(j<n2){
while (j<n2)
result[k++] = arr2[j++];
}
void main(){
int arr1[10], arr2[10], result[20], i;
int clrscr();
cout << "Enter 10 numbers [arr1]: ";
for (i = 0; i<10; i++)
cin >> arr1[i];
cout << "\nEnter 10 numbers [arr2]: ";
for (i = 0; i<10; i++)
cin >> arr2[i];
int item = mrg_sort(arr1, 10, arr2, 10, result);
cout << "\n\nAfter sort : ";
for (i = 0; i<item; i++)
cout << result[i] << " ";
Yes it would. I haven't fixed all your errors just one, mismatched brackets
You need to specifically mention which errors you are not able to solve, so that forum members do not have to explicitly spend their time on building, solving errors and posting back.
What this means is that the 'if' should only have two branches: either you take from arr1 or you take from arr2.
Line 31: you forgot to return k
Suggestions
Lines 23,26,27,30 are unnecessary.
Line 34 -- I think you meant to invoke the function, right? (You want the screen cleared?) Right now you have declared a function prototype. Get rid of 'int'.
Syntax errors, illegal else without matching if, issuing function header (old-style formal list), and else if: identifier not found are the errors from the code below. I would appreciate a correction of these codes.
Line 16,27: elseif is not valid else and if are separate keywords.
My compiler reports:
error C3861: 'elseif': identifier not found
That's pretty clear there is something wrong with elseif.
Line 31: Still missing a return statement.
Line 32: main must always be type int.
You have been asked to use code tags. PLEASE DO SO. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I will not respond further until you apply code tags.