Newbie C++ programmer here :)
I'm supposed to bubble sort an array to where I can eventually print it ascending and descending in the correct order. I am, however, having trouble passing the parameters for the bubbleSort and printElements functions.
I get the error:
error C2664: 'bubbleSort' : cannot convert parameter 1 from 'int []' to 'int'
Thanks for any help :)
#include <stdio.h>
#include <iostream>
using namespace std;
void bubbleSort(int,int);
void printElements(int, int);
int main()
{
int maxIntegers=10;
int integers[10];
int i=0;
cout << "Please enter 10 integers : \n\n";
while ( i < maxIntegers)
{
cin >> integers[i];
i++;
}
bubbleSort(integers,10);
printElements(integers,10);
}
void bubbleSort(int *array,int length)//Bubble sort function
{
int h,j;
for(h=0;h<10;h++)
{
for(j=0;j<h;j++)
{
if(array[h]>array[j])
{
int temp=array[h]; //swap
array[h]=array[j];
array[j]=temp;
}
}
}
}
void printElements(int *array,int length) //print array elements
{
int i=0;
for(i=0;i<10;i++)
{
cout<<array[i]<<endl;
}
}