气泡排序错误LNK2019

BubbleSort error LNK2019

本文关键字:LNK2019 错误 排序 气泡      更新时间:2023-10-16

这是我的cpp代码和错误,我得到

错误LNK2019:无法解析的外部符号"void __cdecl selectionSort(int * const,int &,int &)"(?selectionSort@@YAXQAHAAH1@Z)引用函数_main

#include <iostream>
using namespace std;
void bubbleSort(int[], int&, int&);
void inserionSort (int [], int&, int&);
void generateRandomArray ( int [], int [], int []);
void selectionSort (int[], int&, int&);
const int length=5000;

  int main()
    {
        int compBubbleSort =0;
        int assignBubbleSort=0;
        int list1[length], list2 [length], list3[length];
    generateRandomArray( list1, list2, list3);
    cout<<"****************Bubble sort*****************"<<endl;
    bubbleSort( list1, compBubbleSort, assignBubbleSort);
    cout<<endl;
    cout<<"Number of compBubbleSort are :"<< compBubbleSort<<endl;
    cout<<"Number of  Assignments are :"<< assignBubbleSort<<endl;
    cout<<endl;
    compBubbleSort = 0;
    assignBubbleSort = 0;
    cout<<"**********Selection sort***************"<<endl;
    cout<<endl;
    selectionSort (list2, compBubbleSort, assignBubbleSort);
    cout<<"Number of compBubbleSort are:"<< compBubbleSort <<endl;
    cout<<"Number of  Assignments are :"<< assignBubbleSort<<endl;
    cout<<endl;
    compBubbleSort=0;
    assignBubbleSort=0;
    cout<<"****************Insertion sort*******************"<<endl;
    cout<<endl;
    inserionSort (list2, compBubbleSort, assignBubbleSort);
    cout<<"Number of compBubbleSort are:"<< compBubbleSort <<endl;
    cout<<"Number of  Assignments are :"<< assignBubbleSort<<endl;
    system ("pause");
    return 0;
}
void generateRandomArray( int list1[], int list2 [], int list3[])
{
    srand(time_t(0));
    for(int i=0; i<length; i++)
        list1 [i]= list2[i]= list3[i]=rand()%20000;
}
void bubbleSort (int num[], int &compBubbleSort, int &assignBubbleSort)
{
    for(int iter=1; iter<length; iter++)
    {
        for(int index=1; index<length; index++)
        {
            compBubbleSort++;
            if(num [index]>num[index+1])
            {
                int temp= num[index];
                num[index] = num[index+1];
                num[index+1]=temp;
                assignBubbleSort++;
            }
        }
    }
}
void seletionSort( int num[], int &compBubbleSort, int &assignBubbleSort)
{
    int index;
    int smallestIndex;
    int location;
    int temp;
    for (index=0; index<length-1; index++)
    {
        smallestIndex=index;
        for(location=index+1;location<length;location++)
        {
            compBubbleSort++;
            if(num[location]<num[smallestIndex])
            {
                smallestIndex=location;
            }
        }
         temp= num[smallestIndex];
         num[smallestIndex] =num[index];
         assignBubbleSort= assignBubbleSort+3;
         num[index] = temp;
    }
}
void inserionSort (int num[], int &compBubbleSort, int&assignments)
{
    int firstOutOfOrder,location;
    int temp;
    for (firstOutOfOrder=1; firstOutOfOrder<length;firstOutOfOrder++)
    {
        if(num[firstOutOfOrder]<num[firstOutOfOrder-1])
        {
        compBubbleSort++;
        temp= num[firstOutOfOrder];
        location=firstOutOfOrder;
        assignments=assignments+2;
            do
            {
                num[location]=num[location-1];
                assignments++;
                location--;
                compBubbleSort++;
            }
            while(location>0 &&num[location-1]>temp);
            num[location]=temp;
            assignments++;
        }   
    }
}

谁能解释一下错误2019,因为我的大多数程序都有。

函数定义中有一个错别字

改变:

void seletionSort( int num[], int &compBubbleSort, int &assignBubbleSort)

:

void selectionSort( int num[], int &compBubbleSort, int &assignBubbleSort)
//       ^

链接器找不到selectionSort