addressing pointer instead of int

Hi guys,
I have problem with initialization of insert sort.Actually I´m trying to do it for the first time so I have here maybe more bucks,but the point is that in initialization I can´t get the first int,I think I must address it by a pointer but I don´t fully understand them yet so can you give me please someone any solution how to do it?

Thank you!

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
  #include <iostream>

using namespace std;

void insertionsort ( int arr[],int n)
{
    int i,key,j ;
    for ( i=1 ; i<n ; i++)
    {
        key = arr[i] ;
        j = i- 1 ;

        while (j >= 0 && arr[j] > key)
        {
            arr[j+1] = arr[j] ;
            j = j-1 ;
        }
        arr [j+1] = key ;
    }

}
int main()
{
    insertionsort( 10, 15) ; // here is the problem,debugger says:invalid conversion from ´int´ to ´int*´ //
    return 0;
Hello LandaBanda,

Welcome to the forum.

The problem is that in main you are calling "insertionsort" with two numbers, but the "insertionsort"function is defined as taking an "array" and an "int". The error messag is saying that it can not convert a single number, 10, to an array.

When the function is called the calling parameters need to match the parameters in the function definition or the prototype.

To fix this you will need to define an array in main an pass this as your first parameter when you call the "insertionsort" function.

Hope that helps,

Andy
Topic archived. No new replies allowed.