⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertsort.c

📁 插入排序
💻 C
字号:
#include <stdio.h>
#include "buildarray.c"
#include "sort.h"

unsigned long int compare=0,move=0;


void InsertSort(int *p,int n)
{
	int i,j,temp,count=0;
	for(i=1;i<n;i++){	//认为只有一个数的情况下已经是排好序,故i=0不考虑	
		temp=*(p+i);
		move++;
		for(j=i-1;j>=0;j--){
			if(temp>=*(p+j))
				break;
			else{ 
				*(p+j+1)=*(p+j);
				move++;
			}
			compare++;
		}
		*(p+j+1)=temp;
		move++;
	}
	printf("the queue sorted by insertsort is:\n");
	for(i=0;i<n;i++){
		printf("%d	",*(p+i));
		count++;
		if(count%10==0)
		printf("\n");
	}
}


main()
{
	//int Queue[9]={8,5,6,9,2,1,3,4,7};
	InsertSort(BuildArray(),NUM);
	printf("InsertSort compare=%ld,move=%ld",compare,move);
	printf("\n");	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -