int main (void) { int array1[10]; int array2[10]; int merge[20]; int i; int j; int n; int m; int l; int temp; int mergearray(int array1[], int array2[], int merger[], int n, int m); printf("Enter the array1 values how many do you want\n "); scanf("%d", &n); printf("Enter the array1 values\n "); for (l = 0; l < n; ++l) { scanf("%i", &array1[l]); } printf("Enter the array2 values how many do you want\n"); scanf("%d", &m); printf("Enter the array1 values\n "); for (l = 0; l < m; ++l) { scanf("%i", &array2[l]); } /* sorting array1 */ for (i = 0; i < n; ++i) { for (j = i; j < n; ++j) { if(array1[i] > array1[j]) { temp = array1[i]; array1[i] = array1[j]; array1[j] = temp; } } } /* sorting array2 */ for (i = 0; i < m; ++i) { for (j = i; j < m; ++j) { if(array2[i] > array2[j]) { temp = array2[i]; array2[i] = array2[j]; array2[j] = temp; } } } mergearray(array1, array2, merge, m, n); printf("Sorted array\n"); for (l = 0; l < n + m; ++l) { printf("%i\n", merge[l]); } return 0; }
void mergesort(long long a[],int first,int last,long long temp[]) { int mid = (first + last)/2; if(first != last) { mergesort(a,first,mid,temp); mergesort(a,mid+1,last,temp); mergearray(a,first,mid,last,temp); } }
void mergesort(int a[], int first, int last, int temp[]) { if (first < last) { int mid = (first + last) / 2; mergesort(a, first, mid, temp); mergesort(a, mid + 1, last, temp); mergearray(a, first, mid, last, temp); } }
void mergesort(struct kit *a, int first, int last, struct kit *temp) { if (first < last) { int mid = (first + last) / 2; mergesort(a, first, mid, temp); //左边有序 mergesort(a, mid + 1, last, temp); //右边有序 mergearray(a, first, mid, last, temp); //再将二个有序数列合并 } }
void mergesort(vector<int>& a,int first,int last,vector<int>& temp) { if(first<last) { int mid=(first+last)/2; mergesort(a,first,mid,temp); mergesort(a,mid+1,last,temp); mergearray(a,first,mid,last,temp); } }
void Merge_Sort(int array[],int first,int last,int temp[]) { int mid; if(first<last) { mid=(first+last)/2; Merge_Sort(array,first,mid-1,temp);//左边有序 Merge_Sort(array,mid+1,last,temp);//右边有序 mergearray(array,first,mid,last,temp);//将两个有序队列合并 } }
inline void mergersort::mergesort(int arr[], int first, int last, int temp[]) { if (first >= last) { return; } int mid = (first + last) / 2; mergesort(arr, first, mid, temp); //左边有序 mergesort(arr, mid + 1, last, temp); //右边有序 mergearray(arr, first, mid, last, temp); //再将二个有序数列合并 }