插入排序

void swap(int& a, int& b) {
	int temp = a;
	a = b;
	b = temp;
}
void insert_sort(int nums[], int len)
{	
	for (int i = 1; i < len; i++) {   //从第二个数开始
	    if(num[i]<num[i-1]){         //后一个数比前一个数要小的话
	        int j, temp=num[i];      //先保存后一个较小的数到temp
	        for (j = i-1; num[j] > temp; --j) {   //把比这个较小的数temp大的数往后移一位,给这个较小的数腾出位置
	            num[j+1]=num[j];
			}
			num[j+1]=temp;   //把较小数temp放在腾出来的位置上
		}
	}		
}

选择排序 :https://blog.csdn.net/qq_43657442/article/details/103716989

快速排序 :https://blog.csdn.net/qq_43657442/article/details/103716839

冒泡排序 :https://blog.csdn.net/qq_43657442/article/details/103716226

posted on 2021-06-09 22:24  雾恋过往  阅读(33)  评论(0编辑  收藏  举报

Live2D