program not giving any output


using namespace std;
template<class T>
void Bubblesort() {
T *unsorted, swap;
unsorted = new T[999];
srand(time(NULL));
cout << "1" << endl;
for (int i = 0; i < 999; i++) {
unsorted[i] = rand() % 1000;
cout << unsorted[i] << endl;
}
int start_s = clock();
for (int i = 0; i < 999; i++)
{
for (int j = 0; j < 998; j++)
{
if (unsorted[j] > unsorted[j + 1])
{
swap = unsorted[j];
unsorted[j] = unsorted[j + 1];
unsorted[j + 1] = swap;
}
}
}
int stop_s = clock();
cout << "time taken: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << endl;
for (int i = 0; i < 999; i++) {
cout << unsorted[i] << endl;
}
};

int main() {

void Bubblesort();
system("pause");
return 0;
}
1
2
3
4
5
6
int main() 
{
   void Bubblesort();
   system("pause");
   return 0;
}


You declare a function Bubblesort inside main instead of calling it.
From what Thomas1974 said :

==>
1
2
3
4
5
6
int main()
 {
   void Bubblesort<???>();
   system("pause");
   return 0;
 }
Last edited on
1
2
template<class T>
void Bubblesort(){}


This template function has one template parameter <class T>, meaning it requires at least one argument. Simply calling Bubblesort() will not work. You must supply the <class T> in order to be able to call this function.

For example :
1
2
Bubblesort<int>();
Bubblesort<double>();
Last edited on
Does that help you? :)
Topic archived. No new replies allowed.