我正在使用插入排序函数对 5000 int 升序数组进行排序。当我将数组的地址传递给函数调用时,我得到 [Error] name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]。也许我应该使用 vector ,但我不熟悉它们。也许我编码有误?
#include <iostream>
#define SIZE 5000 //array size
using namespace std;
void insertionSort(int arr[], int length) {
int i, j, tmp;
for (i = 1; i < length; i++) {
j = i;
while (j > 0 && arr[j - 1] > arr[j]) {
tmp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = tmp;
j--;
}
}
}
int main() {
int a[SIZE];
int count = 1;
for(int i=0; i<SIZE; i++) {
a[i] = count;
count++;
}
for(int i = 0; i < SIZE; i++) {
printf("%d\t", a[i]);
}
insertionSort(&a[i], SIZE);
}
最佳答案
你可能想打电话
insertionSort(a, SIZE)
关于c++ - 在数组c++上调用排序函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30042069/