[問題] 想請教一下std::list的rend/rbegin 的for迴圈用法
看板C_and_CPP (C/C++)作者donkeychen (Bad_To_The_Bone)時間11年前 (2014/07/16 16:00)推噓1(1推 0噓 6→)留言7則, 3人參與討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
c++
問題(Question):
看到一段code
看起來是把有序的list由後往前取item來用
想請教一下為何 for迴圈會用 ++rit 而非 --rit呢
程式碼(Code):(請善用置底文網頁, 記得排版)
std::list<int> orderedlist;
std::list<int>::const_reverse_iterator orderedlist_rend = orderedlist.rend();
for(std::list<int>::const_reverse_iterator rit = orderedlist.rbegin();
rit!=orderedlist_rend;
++rit)
{
use *rit;
}
假設 orderedlist = {1, 2, 3, 4, 5}
請問 rbegin()是在這邊嗎?
^
|
rbegin()
rend()又會是在哪邊呢?
<--------方向
總覺得好像該由大往小..
感謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.59.147.226
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1405497644.A.A82.html
※ 編輯: donkeychen (210.59.147.226), 07/16/2014 16:02:00
推
07/16 16:17, , 1F
07/16 16:17, 1F
→
07/16 16:19, , 2F
07/16 16:19, 2F
→
07/16 16:20, , 3F
07/16 16:20, 3F
→
07/16 16:31, , 4F
07/16 16:31, 4F
→
07/17 15:04, , 5F
07/17 15:04, 5F
→
07/17 15:05, , 6F
07/17 15:05, 6F
→
07/17 15:05, , 7F
07/17 15:05, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章