-2
我正在使用Microsoft Visual Studio編譯代碼。我得到while循環這個錯誤的條件a[i] > k
:在while循環'>'中獲取錯誤:沒有從'int'轉換爲'int *'
'>':從 '詮釋' 沒有轉化爲 '詮釋*'
下面是代碼:
/* Sort the array using Recursive insertion sort */
#include <stdio.h>
#include <conio.h>
void RecursiveInsertionSort(int a[], int);
/* Recursively call the function to sort the array */
void RecursiveInsertionSort(int *a, int n)
{
int i,k;
if (n > 1)
RecursiveInsertionSort(a, n - 1);//Call recursively
else {
k = a[n];
i = n - 1;
while (i >= 0 & & a[i] > k){
a[i + 1] = a[i]; //replace the bigger
i = i - 1;
}
a[i + 1] = k; //Place the key in its proper position
}
}
/* Main function */
void main()
{
int a[] = { 5,4,3,2,1 }; // Array unsorted declared
RecursiveInsertionSort(a, 5);//call recursive function to sort the array in ascending order
}
任何人都可以請幫我理解錯誤嗎?
這是「&」號之間的空格嗎? – Li357
謝謝..遺憾的錯誤 – Sandeep