關於冒泡排序

#include <stdio.h>

#include <string.h>//sizeof(數組名)是string.h裏面的函數 

int main(){

//冒泡 

int a[] ={1,0,9,6,7,3,7,5,8};

int temp;


int length =  sizeof(a) / sizeof(int) ;

printf("length=%d",length);

for(int i = length-1 ;i >= 0;i--){

for(int j = 0;j < i;j++){

if(a[j] > a[j+1]){

temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

for(int i = 0;i < length;i++){

printf("%d\n",a[i]);

}

return 0;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章