我有一个非常简单的(或者至少应该是)赋值,我必须在大量的随机数上运行bubblesort并查看它的执行时间。然后我必须做同样的事情,除了将数组分成一半,并在另一个线程中对另一个线程中的另一个线程进行排序,并且看看它是否更快。Bubblesort with C
我从来没有使用C之前,所以我完全无能为力指针,只有与Java一起工作。这里是我的代码,因为我只是想让bubblesort工作。
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <libgen.h>
int main() {
int *array[50000];
for(int i = 0; i < 50000; i++) {
array[i] = 1;
}
bubbleSort(array, 50000);
}
void bubbleSort(int *numbers[], int *array_size) {
int i, j, temp;
for(i = (array_size - 1); i > 0; i--) {
for(j = 1; j <= i; j++) {
if(numbers[j-1] > numbers[j]) {
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
for(int i = 0; i < 10; i++) {
printf(numbers[i]);
}
}
我想在这里做的所有事情是排序数组,然后打印出前十个数字,所以我知道它的工作。我收到各种指针错误。
"bubbleSort.c", line 11: warning: improper pointer/integer combination: op "="
"bubbleSort.c", line 13: warning: implicit function declaration: bubbleSort
"bubbleSort.c", line 16: identifier redeclared: bubbleSort
current : function(pointer to pointer to int, pointer to int) returning void
previous: function() returning int : "bubbleSort.c", line 13
"bubbleSort.c", line 18: warning: improper pointer/integer combination: op "="
"bubbleSort.c", line 21: warning: improper pointer/integer combination: op "="
"bubbleSort.c", line 23: warning: improper pointer/integer combination: op "="
"bubbleSort.c", line 28: warning: argument #1 is incompatible with prototype:
prototype: pointer to const char : "/usr/include/iso/stdio_iso.h", line 206
argument : pointer to int
cc: acomp failed for bubbleSort.c
'阵列[i] = 1;'我知道,通过公平的掷骰和所有的决定,但是这不是与“随机数的阵列”旨在测试性能。 –
哎呀,我改变了这一点,因为我得到了一个错误,并忘记在发布之前将它改回来。而不是一个我有rand()那里,但它不喜欢那个。现在让我改回它,看看错误是什么。 – user1704677