Advertisement
wendy890711

190527template

May 27th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. template<class T>
  6. int comp(T min[],int size)
  7. {
  8. int minn=min[0],index=0;
  9. for (int i=0; i < size; i++)
  10. {
  11.  
  12. if (min[i] < min[index])
  13. {
  14. minn = min[i];
  15. index = i;
  16. }
  17. }
  18. return minn;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. int all[] = { 20, 17, 39, 18, 22, 46 };
  25. double another[] = { 7.65, 3.4, 2.11, 1.5, 4.33 };
  26.  
  27. cout << "all裡最小值是:" << comp<int>(all, sizeof(all)/sizeof(int)) << endl;
  28. cout << "another裡最小值是:" << comp<double>(another, sizeof(another)/sizeof(double)) << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement