Hi! I have written the following piece of code, it compiles and works fine, i can enter data in it, but the proble is: when i am tryng to dusplay entered data(numbers in my case) it crashes. I thnks that i am missng one small line of code, could anyone please tell me which line is it, and where am i suppose to put it? thanks.
Code:#include <stdio.h> #include <iostream> #include <iomanip> using namespace std; void mergesort(int [], int [], int [], int, int); int main() { int A[50], B[50], C[100], m, n, i; cout << "*****************************************************************************" << endl; cout << setw(45) << " MERGE SORT PROGRAM " << endl; cout << "*****************************************************************************" << endl; cout << " How many elements would you like to have in your first array? (max 50): " << endl; cin >> m; cout << " Please enter the array of elements in ascending order: " << endl; for (i=0; i<m; i++) cin >> A[i]; cout << " How many elements would you like to have in your second array? (max 50): " << endl; cin >> n; cout << " Please enter the array of elements in ascending order:" << endl; for (i=0; i<n; i++) cin >> B[i]; mergesort(A, B, C, m, n); cout << "\n------The result of your sorted arrays is----" << endl; for (i=0; i<m+n; i++) cout << C[i]; return 0; } void mergesort(int A[], int B[], int C[], int m, int n) { int a=0, b=0, c=0; for (a=0, b=0, c=0; a<m && b<n;) { if (A[a]<B[b]) C[c++] = A[a++]; else C[c++] = B[b++]; } if (a<m) while (a<m) C[c++] = A[a++]; else while (b<n) C[c++] = B[b++]; }



LinkBack URL
About LinkBacks



