From b7643e8271a7821de71a6d41f1e7e50ca128546e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 23 Oct 2014 10:10:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=85=A8=E9=83=A8deque?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Deque.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/TinySTL/Deque.h b/TinySTL/Deque.h index b6f3ada..0f52bf3 100644 --- a/TinySTL/Deque.h +++ b/TinySTL/Deque.h @@ -234,7 +234,6 @@ namespace TinySTL{ void init(){ mapSize_ = 2; map_ = getANewMap(mapSize_); - //map_[mapSize_ - 1] = getANewBuck(); beg_.container_ = end_.container_ = this; beg_.mapIndex_ = end_.mapIndex_ = mapSize_ - 1; beg_.cur_ = end_.cur_ = map_[mapSize_ - 1]; @@ -255,7 +254,7 @@ namespace TinySTL{ template void deque_aux(Iterator first, Iterator last, std::false_type){ difference_type mid = (last - first) / 2; - for (auto it = first + mid; it >= first; --it) + for (auto it = first + mid; it != first - 1; --it) (*this).push_front(*it); for (auto it = first + mid + 1; it != last; ++it) (*this).push_back(*it); @@ -292,10 +291,19 @@ namespace TinySTL{ deque(); deque_aux(first, last, typename std::is_integral::type()); } - /*template + template deque::deque(const deque& x){ - - }*/ + mapSize_ = x.mapSize_; + map_ = getANewMap(mapSize_); + for (int i = 0; i + x.beg_.mapIndex_ != x.mapSize_; ++i) + for (int j = 0; j != getBuckSize(); ++j) + map_[x.beg_.mapIndex_ + i][j] = x.map_[x.beg_.mapIndex_ + i][j]; + beg_.mapIndex_ = x.beg_.mapIndex_; + end_.mapIndex_ = x.end_.mapIndex_; + beg_.cur_ = map_[beg_.mapIndex_] + (x.beg_.cur_ - x.map_[x.beg_.mapIndex_]); + end_.cur_ = map_[end_.mapIndex_] + (x.end_.cur_ - x.map_[x.end_.mapIndex_]); + beg_.container_ = end_.container_ = this; + } template void deque::reallocateAndCopy(){ auto newMapSize = getNewMapSize(mapSize_);