Have a small problem with my insertion sort

I have a really small problem with my insertion sort and I cannot figure it out.

my program is set up to take an unlimited amount of random values as input after the prompt my only problem is when I put my insertion sort function inside my main function and I have a small problem with the parameters. it says expected an expression. I have comments marked at the problem.

What am I doing wrong?


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
32
33
34
35
36
37
38
39
40
41
#include <iostream>
//#include <algorithm>
using namespace std;


int a[];
int n;
int key;
void insertionSort(int a[], int n)
	{
		
		int i, j;
		for (i=1; i<=n ; i++)
		{
			key = a[i];
			j=i-1;
			while(a[j]> key&&j>=0)
			{
				a[j+1]=a[j];
				j--;
			}
			if(j+1 != i){ 
			a[j+1]=key;
			}
			cout<<a[j];
		}

					
}

	

int main()
{
cout<<"Please enter a random series of values: ";
cin>>n; 
cout<<endl;
insertionSort(a[], n);//my problem is the array a[] says expected an expression
	system ("PAUSE");
	return 0;
}



Please help
Thank You!!!!
remove the [] from your function call.
Thanks for the reply Lowest
your suggestion worked but it's now giving me an error saying
Error 1 error LNK2001: unresolved external symbol "int * a" (?a@@3PAHA)
Error 2 error LNK1120: 1 unresolved externals 1 1 sortAlgorithms

what does this mean???
When you declare the array, you need a size. You should bring the declaration of a[] and n to main:
1
2
3
4
5
const int n = 10;
int arr[n];

// fill array with values;
// sort array 
Topic archived. No new replies allowed.