用C ++传递参数?

时间:2015-06-15 06:35:27

标签: c++ arrays sorting parameter-passing heapsort

所以我正在尝试实现堆排序,而我遇到参数传递部分的问题。总的来说,我有这个:

int main() {

int array[5];

heapsize = (sizeof(array) / sizeof(*array));

std::cout << "Input 5 integers separated by spaces:" << std::endl;
for (int i = 0; i < 5; ++i)
{
    std::cin >> array[i];
}
cout << "main length of a: " << (sizeof(array) / sizeof(array[0])) << endl;


heapSort(array);

cout << "final output:" << endl;

for (int i = 0; i < 5; ++i)
    cout << array[i] << "  ";

return 0;
}

我在数组中读取,并将其传递给heapSort(array)

然后我这样做:

void heapSort(int A[])
{
int n; 
n = (sizeof(A)/sizeof(A[0])); 
cout << "This is n: " << n << endl; //prints out n = 1 
build_max_heap(A); 
}

我的意思是将array[5]传递给heapsort(int A[]),为什么长度显示为1?

0 个答案:

没有答案