冒泡排序

软件工程马搏 edited 4 年前

include

int main()
{
int n,z;
scanf(“%d”,&n);
int data[n];
for(z=0;z<=n-1;z++)
{scanf(“%d”,&data[z]);}
int tmp;
int i, j;

for (i=0; i<sizeof(data)/sizeof(int)-1; i++)
{
    for (j=0; j<sizeof(data)/sizeof(int)-1-i; j++)
    {
        if (data[j] > data[j+1])
        {
            tmp       = data[j+1];
            data[j+1] = data[j];
            data[j]   = tmp;
        }
    }
}

for (i=0; i<sizeof(data)/sizeof(int); i++)
{
    printf("%d ", data[i]);
}
printf("\n");

return 0;

}

Comments