I'm trying to understand this algorithm from J.F. Sebastian, but I try to compile it
(gcc/g++ 4.8
) get a strange compiler error:
const int n=101,m=31,k=*16-1;
int i;
srand(time(NULL));
for(i=0;i<n;i++) x[i]=rand();
std::sort(x,x+m,std::greater<float>());
std::sort(x+m,x+n,std::greater<float>());
float v=nsmallest_iter(x,x+m,x+m+1,x+n,n-1-k,std::greater<float>());
Edit
adding the -std=c++11
flag I get:
from blabla.cpp:2:
blabla.cpp: In instantiation of ‘typename std::iterator_traits<_Iterator>::value_type nsmallest_iter(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, size_t, Compare) [with RandomAccessIterator = float*; Compare = std::greater<float>; typename std::iterator_traits<_Iterator>::value_type = float; size_t = long unsigned int]’:
blabla.cpp:58:64: required from here
blabla.cpp:28:66: error: ‘issorted’ was not declared in this scope
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
blabla.cpp:28:35: error: ‘issorted’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
blabla.cpp:28:66: note: ‘issorted’ declared here, later in the translation unit
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
Anybody knows how to fix this?