C语言常见排序之冒泡排序
#include<stdio.h>
void BubbleSort(int *Array,int Length)
{
int i= 0,j = 0,temp = 0;
for(i = 0; i < Length – 1; i++)
{
for(j = 0; j < Length-i-1; j++)
{
if(Array[j] > Array[j+1])
{
temp = Array[j];
Array[j] = Array[j+1];
Array[j+1] = temp;
}
}
}
}
{
int i= 0,j = 0,temp = 0;
for(i = 0; i < Length – 1; i++)
{
for(j = 0; j < Length-i-1; j++)
{
if(Array[j] > Array[j+1])
{
temp = Array[j];
Array[j] = Array[j+1];
Array[j+1] = temp;
}
}
}
}
int main(void)
{
int i = 0;
int ArrayBuf[5] = {2,1,0,4,3};
{
int i = 0;
int ArrayBuf[5] = {2,1,0,4,3};
BubbleSort(&ArrayBuf[0],sizeof(ArrayBuf)/sizeof(int));
for(i = 0; i <( sizeof(ArrayBuf)/sizeof(int));i++)
{
printf(“%d “,ArrayBuf[i]);
}
}
{
printf(“%d “,ArrayBuf[i]);
}
}
版权声明:本文为HMM0530原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。