Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inproving deque description and fixing the example #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Data Structures and Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ v.clear();
**Use for**
* Similar purpose of `std::vector`
* Basically `std::vector` with efficient `push_front` and `pop_front`
* More efficient management of dinamically growth than `std::vector`

**Do not use for**
* C-style contiguous storage (not guaranteed)
* Access by adding a offset to an iterator (do not use `iterator + index`)

**Notes**
* Pronounced 'deck'
Expand Down Expand Up @@ -149,9 +151,9 @@ std::deque<int> d;
//---------------------------------

// Insert head, index, tail
d.push_front(value); // head
d.insert(d.begin() + index, value); // index
d.push_back(value); // tail
d.push_front(value); // head
d.insert(std::next(d.begin(), index), value); // index with std::next
d.push_back(value); // tail

// Access head, index, tail
int head = d.front(); // head
Expand All @@ -167,9 +169,9 @@ for(std::deque<int>::iterator it = d.begin(); it != d.end(); it++) {
}

// Remove head, index, tail
d.pop_front(); // head
d.erase(d.begin() + index); // index
d.pop_back(); // tail
d.pop_front(); // head
d.erase(std::next(d.begin(), index)); // index with std::next
d.pop_back(); // tail

// Clear
d.clear();
Expand Down