Hello, I am in the process of creating a program that accepts random numbers, put them in an array and sort them using different
types of sorting algorithms. I then passed the array as an argument to the "BubbleSort" function, however, when I try to call
the array in the main() function, an error appeared saying "argument of type "int" is incompatible with parameter of type "int *"
Why did that appear? Did I overlook something in the program? It's not finished yet, but here it is:
#include <iostream>
using namespace std;
void BubbleSort(int arr[], int n);
int main()
{
int num, ch, i;
int arr[999] = {};
cout << "Enter number of nodes: ";
cin >> num;
for(i=0; i<num; i++)
{
cout << "Enter node: ";
cin >> arr[i];
}
cout << "\nHere are the unsorted nodes: ";
for(int i=0; i<num; i++)
{
cout <<""<<arr[i]<<" ";
}
choice:
cout << "\n\nChoices are:";
cout << "\n[1] Bubble Sort"
<< "\n[2] Insertion Sort"
<< "\n[3] Selection Sort"
<< "\n[4] Exit"
<< "\nEnter choice: ";
cin >> ch;
switch(ch)
{
case 1:
cout << "\nBubble Sort" <<endl;
BubbleSort(arr[i], num);
cout << "\n"<<arr[i]<<" ";
break;
case 2:
cout << "\nInsertion Sort" <<endl;
break;
case 3:
cout << "\nSelection Sort" <<endl;
break;
case 4:
exit(1);
break;
default:
cout << "\nInvalid entry, try again";
goto choice;
break;
}
system("pause>null");
return 0;
}
void BubbleSort(int arr[], int n)
{
bool swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++) {
if (arr[i] > arr[i + 1]) {
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
swapped = true;
}
}
}
}
Any help would be highly appreciated, I'll be glad if someone will enlighten me with this matter. Thanks! :)