`
mr.zxing
  • 浏览: 68480 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

数据结构--冒泡排序(C语言)

阅读更多
#include <stdio.h>
#include <malloc.h>
void bubbleSort(int* sortArr,int len);

int main(void) {
//	int num[]={3,4,2,1,5,8,7,9,6};
	int counts;

	int i=0;
  
  printf("input your num numbers:\n");
	scanf("%d",&counts);
  int *num = (int *)malloc(counts*sizeof(int));
	for(int j=0;j<counts;j++){
		scanf("%d",num+j);
	}
  int len=counts;
	bubbleSort(num,len);

	
	

	for(i;i<len;i++){
		printf("%d\n",*(num+i));
	}
	return 0;
}

void bubbleSort(int *sortArr,int len){
	int temp;
	for(int i=0;i<len;i++){
			for(int j=0;j<len-i-1;j++){
					if(sortArr[j]>sortArr[j+1]){
							temp = sortArr[j];
							sortArr[j] = sortArr[j+1];
						  sortArr[j+1] = temp;		
					}
			}

	}

}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics