调用"BubbleSort"没有匹配函数

No matching function for call to "BubbleSort"

本文关键字:函数 BubbleSort 调用      更新时间:2023-10-16

你好,我遇到了一个错误问题"调用"BubbleSort"没有匹配的函数。我正在创建一个没有类的BubbleSoot程序。我的BubblySort中的参数与主函数调用匹配,所以我不确定为什么会出现这个错误。有什么想法吗?

我的主要内容如下:

int main()
{
int size = 5000;
int* array = CreateAnArray(size);
BubbleSort(array, size, comparison, itemAssignment);  ///This is where the error is 
}

BubbleSort函数如下所示:

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;
}

*************我的全部代码***********

#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);       
}

中的比较

BubbleSort(array, size, comparison, itemAssignment);

未定义。