0

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?

Community
  • 1
  • 1
user189035
  • 5,589
  • 13
  • 52
  • 112

2 Answers2

1

You are using a C++11 feature, so you have to either use the compile flag

-std=c++11

or

-std=c++0x

for the second problem you are probably missing some header or do have an issue with the code.

edit: issorted does probably refer to std::is_sorted. It is to be found in the include #include <algorithm>

Theolodis
  • 4,977
  • 3
  • 34
  • 53
0

Replace issorted by std::is_sorted.
(Add #include <algorithm> if not present)
(Compile with C++11)

Jarod42
  • 203,559
  • 14
  • 181
  • 302