-3
這是我的cpp的代碼,並獲得冒泡錯誤LNK2019
錯誤LNK2019錯誤林:解析外部符號 「無效__cdecl選擇排序爲(int * const的,詮釋&,詮釋&)」(選擇排序@@ 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,因爲我的大部分節目有它。
'seletionSort' ....使用這個 - >'c'。 – user657267
看起來像一個未定義的引用錯誤。也許它沒有被定義,或者你沒有鏈接庫。 – VermillionAzure
這不是冒泡排序錯誤。再看一遍。事實上,你的大部分程序都證明了這一點。 – EJP