// 题目5:
#include <iostream> #include <cstdlib> using namespace std;
template <typename Type>
void Bubblesort(Type * pArray,int n) { int i,j; Type temp; for(i=0;i<n;i++) { for(j=n-1;j>i;j--) { if(pArray[j]<pArray[j-1]) { temp=pArray[j]; pArray[j]=pArray[j-1]; pArray[j-1]=temp; } } } }
int main() { int test1[10] = {2,66,53,48,3,56,42,28,75,13}; double test2[6] = {1.2, 6.6, 5.3, 4.8, 3.0, 5.6};
int n_test1 = sizeof(test1) / sizeof(int); int n_test2 = sizeof(test2) / sizeof(double); void (* pf1)(int *, int); // declaration of a pointer to the function void (* pf2)(double *, int); // declaration of a pointer to the function
pf1 = Bubblesort; // pf1 points to the function
pf1(test1,n_test1); // using pointer pf1 to invoke the function
// to check the result for(int i = 0; i<n_test1; i++) { cout<<test1[i]<<" "; } cout<<endl;
pf2 = Bubblesort; // pf2 points to the function pf2(test2, n_test2); // using pointer pf2 to invoke the function // to check the result for(int j = 0; j<n_test2; j++) { cout<<test2[j]<<" "; } cout<<endl; system("pause"); return 0; }
自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!