Witam mam pytanie czemu nie sortuje mi w typie float i double?
#include <iostream>
using namespace std;
template <typename T>
T BubbleSort(T tab[], T n, T c){
cout << tab[0] << " " << endl;
cout << tab[1] << " " << endl;
cout << tab[2] << " " << endl;
cout << " -------------------- " << endl;
cout << " -------Petla-------- " << endl;
cout << " -------------------- " << endl;
int i,j;
for (i = 0; i < n-1; i++) {
for (j=0; j< n-1-i; j++)
if (tab[j] > tab[j+1]) {
c = tab[j];
tab[j] = tab[j+1];
tab[j+1] = c;}
}
cout << tab[0] << " " << endl;
cout << tab[1] << " " << endl;
cout << tab[2] << " " << endl;
}
int main()
{
int tab[3] = {30,1,2};
float tab1[3] = {30,1,2};
double tab2[3] = {30,1,2};
BubbleSort(tab,3,3);
BubbleSort(tab1,3,3);
BubbleSort(tab2,3,3);
return 0;
}
||=== Build: Debug in bubble sort (compiler: GNU GCC Compiler) ===|
D:\bubble sort\main.cpp||In function 'int main()':|
D:\bubble sort\main.cpp|31|error: no matching function for call to 'BubbleSort(float [3], int, int)'|
D:\bubble sort\main.cpp|31|note: candidate is:|
D:\bubble sort\main.cpp|5|note: template<class T> T BubbleSort(T*, T, T)|
D:\bubble sort\main.cpp|5|note: template argument deduction/substitution failed:|
D:\bubble sort\main.cpp|31|note: deduced conflicting types for parameter 'T' ('float' and 'int')|
D:\bubble sort\main.cpp|32|error: no matching function for call to 'BubbleSort(double [3], int, int)'|
D:\bubble sort\main.cpp|32|note: candidate is:|
D:\bubble sort\main.cpp|5|note: template<class T> T BubbleSort(T*, T, T)|
D:\bubble sort\main.cpp|5|note: template argument deduction/substitution failed:|
D:\bubble sort\main.cpp|32|note: deduced conflicting types for parameter 'T' ('double' and 'int')|
D:\bubble sort\main.cpp||In instantiation of 'T BubbleSort(T*, T, T) [with T = int]':|
D:\bubble sort\main.cpp|30|required from here|
D:\bubble sort\main.cpp|23|warning: no return statement in function returning non-void [-Wreturn-type]|
||=== Build failed: 2 error(s), 3 warning(s) (0 minute(s), 0 second(s)) ===|