mercredi 6 janvier 2016

Algorythm forward_list is sorted ? C++

I have some difficulties in c++11. I would like to create function isSorted which return true if my forward_list is sorted, false if not.

I have imagined a code like that :

template<class T>
bool estTriee(forward_list<T>& list) {
        typename forward_list<T>::iterator it;
        it = list.begin();

        while(it != list.end() &&  *it <= *next(it, 1)) {
            it++;
        }

        return it == list.end();
}

But gcc return me a segmentation fault surrounding the while line.

Can you help me please ?

Thanks a lot

Couim

Aucun commentaire:

Enregistrer un commentaire