Function parameters
Apr 17, 2014 at 5:36am UTC
Hi, I am working on implementing this piece of code right now and I don't understand why I am having errors on line 12 and 14.
It says that both length and arr are undefined, but I thought they included them in my stable_sort function's parameters.
How can I fix this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <iostream>
using namespace std;
int bubble_sort (int arr[], int length)
{
// Implment Bubble Sort
}
int stable_sort (int (*fptr)(int arr[], int length))
{
for (int i = 0; i < length; i++)
{
if (arr[i] == arr[i+1])
{
/*if (key[i] < key[i+1] )
return;*/
}
}
// Check if bubble sort is stable.
}
int main()
{
int arr[]={1,2,4,3,6,5};
int (*pfnc)(int [], int length);
pfnc = bubble_sort;
stable_sort(pfnc);
return 0;
}
Last edited on Apr 17, 2014 at 5:37am UTC
Apr 17, 2014 at 6:47am UTC
They are not stable_sort function parameters. They are parameters of the function passed to stable_sort() as function pointer. Why not just:
int stable_sort (int arr[], int length){ ... }
?
Topic archived. No new replies allowed.