Merge sort algorithm diagram, in fact, is using the idea of divide and conquer to solve. Recursively solve the left half, and then recursively solve the right half. When the left half is one and the left half is one and the left half is two and the left and right sides are swapped, and so on and so forth. Take a look at the dynamic diagram below

#include <stdio.h> void merge(int a[],int tmp[],int left,int right,int rightend) { int leftend=right-1; int tmpa=left; int len=rightend-left+1; while(left<=leftend&&right<=rightend) { if(a[left]<=a[right]) { tmp[tmpa++]=a[left++]; }else if(a[right]<a[left]) { tmp[tmpa++]=a[right++]; } } while(left<=leftend) { tmp[tmpa++]=a[left++]; } while(right<=rightend) { tmp[tmpa++]=a[right++]; } for(int i=0; i<len; i++,rightend--) { a[rightend]=tmp[rightend]; } } void print(int len,int data[]) { for(int i=0; i<len; i++) { printf("%d\t",data[i]); }} int main () {int a [10] = {,7,13,15,19,21,10,13,17,19, 3}; int left=0; int r=6; int rightend=9; int tmp[12]={}; merge(a,tmp,left,r,rightend); int len=sizeof(a)/sizeof(a[0]); print(len,a); }Copy the code