예제 #1
0
int main()
{
    SqList L;
    int N;
    printf("元素个数:");
    scanf("%d",&N);
    CreateSqList(L,N);
    BInsertSort(L);
    return 0;
}
예제 #2
0
int main()
{
	int i = 0;
	int arr[] = {5, 2, 2, 1, 7, 6, 8, 9, 4};
	int r[10];
	for(i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i)//要转换一下,数组的第一个位置不能存放数据
		r[i+1] = arr[i];
	BInsertSort(r, sizeof(arr)/sizeof(arr[0]));
	for(i = 1; i <  sizeof(r)/sizeof(r[0]); ++i)
		printf("%d\t", r[i]);
	printf("\n");
	return 0;
}//main
예제 #3
0
 void main()
 {
   RedType d[N]={{49,1},{38,2},{65,3},{97,4},{76,5},{13,6},{27,7},{49,8}};
   SqList l1,l2,l3;
   int i;
   for(i=0;i<N;i++) /* 给l1.r赋值 */
     l1.r[i+1]=d[i];
   l1.length=N;
   l2=l3=l1; /* 复制顺序表l2、l3与l1相同 */
   printf("排序前:\n");
   print(l1);
   InsertSort(&l1);
   printf("直接插入排序后:\n");
   print(l1);
   BInsertSort(&l2);
   printf("折半插入排序后:\n");
   print(l2);
   P2_InsertSort(&l3);
   printf("2_路插入排序后:\n");
   print(l3);
 }
예제 #4
0
void testInsertSort()
{
	myRDT d[N]={{49,1},{38,2},{65,3},{97,4},{76,5},{13,6},{27,7},{49,8}};
	mySQLIST l1,l2,l3,l4,l5,l6,l7,l8,l9;
	int i ;
	for(i=0;i<N;++i)
		l1.r[i+1]=d[i];
	l1.length=N;
	l2=l3=l1;
	l5=l1;
	l6=l1;
	l7=l1;
	l8=l1;
	l9=l1;
	printf("еепРг╟:\n");
	print(l1);
	insertSort(l1);
	printf("ж╠╫с╡ЕхКеепР╨С:\n");
	print(l1);
	BInsertSort(l2);
	printf("уш╟К╡ЕхКеепР╨С:\n");
	print(l2);
	printf("2_б╥╡ЕхКеепР╨С:\n");
	p2_insertSort(l3);
	print(l3);

	mySLKT sl1,sl2;
	int *adr;
	tableInsert(sl1,d,N);
	sl2=sl1;
	printf("еепРг╟:\n");
	print2(sl1);
	arrange(sl1);
	printf("l1еепР╨С:\n");
	print2(sl1);
	adr=(int *)malloc((sl2.length+1)*sizeof(int));
	sort(sl2,adr);
	for(i=1;i<=sl2.length;++i)
		printf("adr[%d]=%d ",i,adr[i]);
	printf("\n");
	rearrange(sl2,adr);
	printf("l2еепР╨С:\n");
	print2(sl2);

	int dt[]={5,3,1};
	for(i=0;i<N;++i)
		l4.r[i+1]=d[i];
	l4.length=N;
	printf("еепРг╟: \n");
	shellSort<int>(l4,dt,3,print);
	printf("еепР╨С: ");
	print(l4);

	int d1[N]= {1,2,4,5,6,77,88,99}; //{49,38,65,97,76,13,27,49};
	printf("еепРг╟:\n");
	print3(d1,N);
	printf("еепР╨С:\n");
	bubble_sort(d1,N,print3);

	printf("©ЛкыеепР╨С: \n");
	quickSort(l5);
	print(l5);

	printf("я║тЯеепР╨С: \n");
	selectSort(l6);
	print(l6);

	printf("йВпня║тЯеепР╨С: \n");
	treeSort(l7);
	print(l7);

	printf("╤яеепР╨С: \n");
	heapSort(l8);
	print(l8);

	printf("╧И╡╒еепР╨С: \n");
	mergeSort(l9);
	print(l9);

	myRDT d3[N+2]={{278,1},{109,2},{63,3},{930,4},{589,5},{184,6},{505,7},{269,8},{8,9},{83,10}};
	mySLLIST l10;
	int *adr1;
	intiList1_(l10,d3,N+2);
	printf("еепРг╟(nextсР╩╧ц╩╦Ёж╣):\n");
	print5(l10);
	radixSort<int>(l10,print4);
	printf("еепР╨С(╬╡л╛а╢╠М):\n");
	print5(l10);
	adr1=(int*)malloc(l10.recnum*sizeof(int));
	sSort(l10,adr1);
	sRearrange(l10,adr1);
	printf("еепР╨С(жьее╪гб╪):\n");
	print5(l10);
}