Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <vector.h>
- #include "ex10-2.h"
- using namespace std;
- int main(){
- int arr[]= {100, 90, 90, 90, 40, 20, 10, 10, 10};
- cout << median(arr);
- return 0;
- }
- #ifndef GUARD_102
- #define GUARD_102
- #include <cstddef>
- #include <stdexcept>
- #include <algorithm>
- template <class T, int N>
- T median(T arr[N]){
- // typedef typename vector<T>::size_type vec_sz;
- size_t size = N;
- if(size == 0)
- throw std::domain_error("median of an empty array");
- sort(arr, arr+N);
- size_t mid = size/2;
- return size % 2 == 0 ? (arr[mid] + arr[mid-1]) / 2 : arr[mid];
- }
- #endif
- ====errors====
- make ex10-2
- g++ -Wall -c -g -o ex10-2 ex10-2.cc
- ex10-2.cc: In function βint main()β:
- ex10-2.cc:10: error: no matching function for call to βmedian(int [9])β
- make: *** [ex10-2] Error 1
- Compilation exited abnormally with code 2 at Sun Oct 24 17:42:58
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement