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

📄 bubblesort.c

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

unsigned long int compare=0,move=0;
BubbleSort(int *p,int n)
{
	int i,j,temp;
	//int count=0;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>=i+1;j--){
			if(*(p+j)<*(p+j-1)){
				temp=*(p+j);*(p+j)=*(p+j-1);*(p+j-1)=temp;
				move+=3;
				//printf("i=%d,j=%d\n",i,j);
				//printf("%d,%d,%d,%d,%d,%d,%d,%d,%d\n",Queue[0],Queue[1],Queue[2],Queue[3],Queue[4],Queue[5],Queue[6],Queue[7],Queue[8]);
			}
			compare++;
		}
	}
/*
	printf("the queue sorted by bubblesort is:\n");
	for(i=0;i<n;i++){
		printf("%d	",*(p+i));
		count++;
		if(count%10==0)
		printf("\n");
	}
	printf("BubbleSort compare=%ld,move=%ld",compare,move);
	printf("\n");
*/	
}


main()
{
	int i,count=0;
	int *ptr;
	//int Queue[10]={62,9,33,85,37,86,5,61,2,44};
	ptr=BuildArray();
	printf("build array:\n");
	for(i=0;i<NUM;i++){
		printf("%d	",*(ptr+i));
		count++;
		if(count%10==0)
		printf("\n");
	}
	BubbleSort(ptr,NUM);
	//BubbleSort(Queue,NUM);
	printf("the queue sorted by bubblesort is:\n");
	for(i=0;i<NUM;i++){
		printf("%d	",*(ptr+i));
		count++;
		if(count%10==0)
		printf("\n");
	}
	printf("BubbleSort compare=%ld,move=%ld",compare,move);
	printf("\n");	
}

⌨️ 快捷键说明

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