这是我的代码:
void bubbleSortInventory(article inventory[], int noOfArticles){
int newn;
int check = 0;
while(check != 0){
newn = 0;
for(int i = 1; i <= noOfArticles-1;i++){
if(inventory[i-1].id>inventory[i].id){
swap(&inventory[i-1].id,&inventory[i].id);
newn = i;
}
}//end for-loop
check = newn;
}
}
和交换函数:
void swap(int *number1, int *number2){
int temporaryHolder;
temporaryHolder = *number1;
*number1 = *number2;
*number2 = temporaryHolder;
}
现在问题来了,当我打印出数组 list 时,它似乎没有排序
有人知道我做错了什么吗?
已解决,谢谢
最佳答案
您的函数将 0
分配给 check
...
int check = 0;
...下面的条件是check != 0
...
while(check != 0) {
// ...
}
...永远不会通过条件。
您的 while() {}
循环永远不会执行,因此它永远不会修改传入的数组。
关于c - 使用函数指向数组的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19554242/