※ 引述《aknow (嘎嘎)》之銘言:
: 我還沒寫完
: 不過我覺得 double list 的 end() 有點弱
: 他的 end() 是 0
: 在 STL 通常實做的 list 是環狀的
: 也就是 begin() 的前一個會是 end()
: 所以這時候 end() 是有意義的
: 可以反過來從 end() iterate 到 begin()
: 不過作業中
: 似乎不能對 end() 作 -- 之類的運算
: 也就是雖然他有 bidirectional iterator
: 可是讀取不到 reverse 方向的第一個
: 還是其實是可以的?
是的 當初未了簡化題目 我將 end() 設為 0, instead of a dummy node that
connects back to begin().
One workaround is that whenever you get ListNode* = 0, you assume it is end()
and thus end()'s previous node will be "_tail".
Similiarly, for insert(end(), x), when pos = 0, we should insert the data
to the end of the list (just like "push_back()" as timmylin said). However,
I didn't consider this case in the homework assignment. Therefore, I will not
test this kind of situation. But you are welcome to implement it this way.
Ummm... I think if I will have this homework assignment in the future, I will
change the definition of end() to make it consistent with STL.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.134.21