Hello I am having an error problem "No matching function for call to "BubbleSort". I'm creating a BubbleSort program with no classes. The parameters in my BubbleSort match the function call in main so I am not sure why I am getting this error. Any ideas?
My main looks like this:
int main()
{
int size = 5000;
int* array = CreateAnArray(size);
BubbleSort(array, size, comparison, itemAssignment); ///This is where the error is
}
and the BubbleSort function looks like this:
int BubbleSort(int* array, int size, int comparison, int itemAssignment)
{
bool done = false;
while (!done) {
done = true;
for (int i = 0; i < size - 1; i++) {
if (array[i] > array[i + 1]) {
done = false;
comparison++;
Swap(array, i, i + 1);
}
else
{
itemAssignment++;
}
}
}
cout << "Number of comparisons: " << comparison << "Item Assignments: " << endl;
return comparison;
return itemAssignment;
}
*************My whole code***********
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int* CreateAnArray(int size) {
srand((unsigned)time(0));
int* array = new int[size];
for (int i = 0; i <size; i++) {
int randomnum = 1 + rand() % 100;
array[i] = randomnum;
}
return array;
}
void Swap(int* array, int a, int b)
{
int tmp = array[a];
array[a] = array[b];
array[b] = tmp;
}
int BubbleSort(int* array, int size, int comparison, int itemAssignment)
{
bool done = false;
while (!done) {
done = true;
for (int i = 0; i < size - 1; i++) {
if (array[i] > array[i + 1]) {
done = false;
comparison++;
Swap(array, i, i + 1);
}
else
{
itemAssignment++;
}
}
}
cout << "Number of comparisons: " << comparison << "Item Assignments: " << endl;
return comparison;
return itemAssignment;
}
int get_comparison(int comparison){
return comparison;
}
int get_itemAssignment(int itemAssignment){
return itemAssignment;
}
int main()
{
int size = 5000;
int* array = CreateAnArray(size);
BubbleSort(array, size, comparison, itemAssignment);
}
A comparison in
BubbleSort(array, size, comparison, itemAssignment);
is undefined.