Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <vector.h>
  3. #include "ex10-2.h"
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.   int arr[]= {100, 90, 90, 90, 40, 20, 10, 10, 10};
  9.  
  10.   cout << median(arr);
  11.   return 0;
  12.  
  13. }
  14.  
  15.  
  16. #ifndef GUARD_102
  17. #define GUARD_102
  18.  
  19. #include <cstddef>
  20. #include <stdexcept>
  21. #include <algorithm>
  22.  
  23.  
  24. template <class T, int N>
  25.   T median(T arr[N]){
  26.   //  typedef typename vector<T>::size_type vec_sz;
  27.   size_t size = N;
  28.   if(size == 0)
  29.     throw std::domain_error("median of an empty array");
  30.   sort(arr, arr+N);
  31.   size_t mid = size/2;
  32.   return size % 2 == 0 ? (arr[mid] + arr[mid-1]) / 2 : arr[mid];
  33.  
  34. }
  35.  
  36.  
  37.  
  38. #endif
  39. ====errors====
  40.  
  41.  
  42. make ex10-2
  43. g++ -Wall -c -g -o ex10-2 ex10-2.cc
  44. ex10-2.cc: In function β€˜int main()’:
  45. ex10-2.cc:10: error: no matching function for call to β€˜median(int [9])’
  46. make: *** [ex10-2] Error 1
  47.  
  48. Compilation exited abnormally with code 2 at Sun Oct 24 17:42:58
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement