/*******************
引用頭文件 BubbleSort.h
調用函數 bubbleSort(double list[], int size)
*******************/
#include
#include "BubbleSort.h"
using namespace std;
int main()
{
int list[10] = {3.3, 4.1, 6.3, 2.4, 3.9, 9.4, 4.2, 3.9, 2.5, 7.8};
//int list[10] = {9,8,7,6,5,4,3,2,1,0}; //這組數列是整型,上一組是小數,為了方便切換所以搞了兩排
bubbleSort(list, 10);
for (int i = 0; i < 10; i++)
{
cout<<list[i]<<" ";
}
return 0;
}
頭文件如下:
/****************
起泡排序 bubbleSort
****************/
void bubbleSort(double list[ ], int size)
{
bool changed = true;
do
{
changed = false;
for (int i = 0; i < size - 1; i++)
{
if (list[i] > list[i + 1])
{
double tem = list[i + 1];
list[i + 1] = list[i];
list[i] = tem;
changed = true;
}
}
}while (changed);
return;
}
問題是:我一點編譯,編譯器就報錯,說cannot convert ‘int*' to 'double*' for arguement '1' to void bubbleSort(double*, int)'
int list[10]聲明為
double list[10]