Skip to content

Commit 9569ef0

Browse files
Update Data Structures and Algorithms.md
1 parent 3cc3dd5 commit 9569ef0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Data Structures and Algorithms.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,23 @@ std::vector<int> v;
8383
// General Operations
8484
//---------------------------------
8585

86+
// Size
87+
unsigned int size = v.size();
88+
8689
// Insert head, index, tail
8790
v.insert(v.begin(), value); // head
8891
v.insert(v.begin() + index, value); // index
8992
v.push_back(value); // tail
9093

9194
// Access head, index, tail
9295
int head = v.front(); // head
96+
head = v[0]; // or using array style indexing
97+
9398
int value = v.at(index); // index
94-
int tail = v.back(); // tail
99+
value = v[index]; // or using array style indexing
95100

96-
// Size
97-
unsigned int size = v.size();
101+
int tail = v.back(); // tail
102+
tail = v[v.size()-1]; // or using array style indexing
98103

99104
// Iterate
100105
for(std::vector<int>::iterator it = v.begin(); it != v.end(); it++) {

0 commit comments

Comments
 (0)