The first few days to write the merge sorting algorithm does not want to enter a specific number to be sorted, after the array input is complete, with-1 end. In this way the program can not row 1, some are not very cool, forget, just add an input array with the length of it. The code is as follows:
#include <iostream>using namespace Std;int a[100];int flag;int n;void vector_initial (); void Print_vector (); void Merge_sort (int p,int r); void Merge_combine (int p,int q,int r); int main () {vector_initial (); Merge_sort (0,n);p rint_vector (); return 0;} void Vector_initial () {int i=0;cout<< "Please enter the number of numbers to sort:"; Cin>>n;while (i<n) {cin>>a[i];i++;} n=n-1;} void Print_vector () {for (int i=0;i<n;i++) cout<<a[i]<< ""; Cout<<a[n]<<endl;} void Merge_sort (int p,int R)//merge sort {int q;if (p<r) {q= (p+r)/2; Merge_sort (P,Q); Merge_sort (Q+1,R); Merge_combine (P,q,r);}} void Merge_combine (int p,int q,int r) {int L[100];int r[100];int n1=q-p+1;int n2=r-q;for (int i=1;i<=n1;i++) L[i]=a[p+ i-1];for (int j=1;j<=n2;j++) R[J]=A[Q+J]; l[n1+1]=10000; r[n2+1]=10000;i=1;j=1;for (int k=p;k<=r;k++) {if (L[i]<=r[j]) {a[k]=l[i];i++;} else{a[k]=r[j];j++;}}}
Merge sort modify----to be able to row negative numbers