呼叫" BubbleSort"没有匹配功能

时间:2014-11-01 23:02:18

标签: c++ parameters parameter-passing bubble-sort

你好我有一个错误问题“没有匹配函数来调用”BubbleSort“。我正在创建一个没有类的BubbleSort程序。我的BubbleSort中的参数匹配main中的函数调用所以我不知道为什么我我收到这个错误。有什么想法吗?

我的主要内容如下:

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

1 个答案:

答案 0 :(得分:0)

中的比较
BubbleSort(array, size, comparison, itemAssignment);

未定义。