How do you find the iterator in the middle of two iterators?

前端 未结 4 764
自闭症患者
自闭症患者 2021-01-17 12:51

I\'m trying to convert my implementation of quicksort into a template that can be used with other containers besides a vector.

Originally I used indexes to find the

4条回答
  •  半阙折子戏
    2021-01-17 13:47

    How about something like this?

    bool isMovingFirst = true;
    while(first != last) {
      if(isMovingFirst) {
        ++first;
      } else {
        --last;
      }
      isMovingFirst = !isMovingFirst;
    }
    

提交回复
热议问题