C 尝试做气泡排序

C 尝试做气泡排序,c,C,我想这是C。但我想弄清楚为什么我的气泡排序不起作用。我遵循的是一个现有的示例,因此可能我与该代码的集成不正确,但不太确定 #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if (argc != 2) { printf("%s <student-id>\n", argv[0]); exit(0); }

我想这是C。但我想弄清楚为什么我的气泡排序不起作用。我遵循的是一个现有的示例,因此可能我与该代码的集成不正确,但不太确定

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) 
{
    if (argc != 2) {
        printf("%s <student-id>\n", argv[0]);
        exit(0);
    }

    int i;
    int size = 10000;
    int seed = atoi(argv[1]); 

    srand(seed % 4);

    int *int_array = malloc(sizeof(int)*size);
    for (i = 0; i < size; i++)
    {
        int_array[i] = rand();
    }

    // This part
    int j;
    for (i = 0; i < size; i += 1) {
        for (j = i - 1; j >= 0 && int_array[j] > int_array[j + 1]; j+= 1) {
            swap(int_array,j);
        }
    }


    int failed = 0;
    for (i = 0; i < size; i++)
    {
        if (int_array[i] < int_array[i+1])
        {
            failed = 1;
            break;
        }
    }

    free(int_array);

    return 0;
}
#包括
#包括
int main(int argc,char*argv[])
{
如果(argc!=2){
printf(“%s\n”,argv[0]);
出口(0);
}
int i;
int size=10000;
int seed=atoi(argv[1]);
srand(种子%4);
int*int_数组=malloc(sizeof(int)*大小);
对于(i=0;i=0&&int_数组[j]>int_数组[j+1];j+=1){
交换(int_数组,j);
}
}
int失败=0;
对于(i=0;i
这是我的气泡排序代码:

for (int i = 0; i < size; i += 1) 
{
    for (j = i + 1; j < size; j+= 1) 
    {
        //this for starts from i+1 because I want to compare element int_array[i] whith the rest of the array. Each time this for starts, int_array is sorted from 0 to i-1
        if(int_array[i] > int_array[j]) swap(int_array[i], int_array[j]);
    }
}
for(int i=0;iint_数组[j])交换(int_数组[i],int_数组[j]);
}
}

srand(种子%4)-你到底为什么要这么做?您将种子限制为仅4个可能的值(0、1、2、3)。。为什么?你把它编译成C吗?然后是的,它是C。无论如何,不要用多种语言标记,要果断!什么是
swap(int_数组,j)