search

Home  >  Q&A  >  body text

(C++)为什么需要反向迭代器?

RT。为什么不可以用正向迭代器进行反向遍历?
求各位指点。

PHP中文网PHP中文网2773 days ago340

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:55:20

    I think it’s better to derive both forward and reverse iterators

    • The advantage is

    Traversing from any starting point to any end point of the data structure chain can write code in a concise way, without having to think about it and making mistakes easily.

    • The disadvantage is

    In order to save programmers’ brain power, the data structure may become more bloated, the space cost will increase, and the execution efficiency of reverse iterator may not be high.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:55:20

    Tell me your opinion:

    auto itr = container.end();
    

    At this point *itr you have crossed the line, end() represents the next position of the last element of your container.

    reply
    0
  • Cancelreply