数组做形参的疑问
#include <iostream>
using namespace std;
void InsertEx(int a[], int i);
void InsertSort(int a[], int n)
{
for (int i = 1; i < n; i++)
{
InsertEx(a, i);
// 我的疑问在这里,每次循环的时候,a是怎么找到自己的值得,如果数组名就是指针的话
那么在i == 1的情况下,怎么确定a是2, 而不是4呢?
}
}
void InsertEx(int a[], int i)
{
int temp = a[i];
int test = 0;
int j = i;
while (j > 0 && a[j] < a[j - 1])
{
test = a[j];
a[j] = a[j - 1];
a[j - 1] = test;
j--;
}
a[j] = temp;
}
void main(void)
{
const int n = 5;
int a[n] = {4, 2, 8, 9, 3};
InsertSort(a, n);
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
各位帮我看看,我的疑问都在上面,谢谢大家了