Algoteka
Log in to submit your own samples!

Resizeable array

Problem by oml1111
# Tech tags Title Creator Created date
1 0
2022-07-31 02:43
View all samples for this language (1 verified and 0 unverified)

Using the STL vector | C++ |

By oml1111 |
0 likes

A resizable array class from the C++ Standard Template Library with an \(O(1)\) amortized time append operation.

Code

#include <vector>

int main() {
    std::vector<int> dynamic_array;
    dynamic_array.push_back(5);
}

Further reading

Basic Data Structures from a Low Level Viewpoint: Vectors - courses.cs.ut.ee

References

classes
std::vector en.cppreference.com cplusplus.com
functions
std::vector::push_back en.cppreference.com cplusplus.com

Problem Description

Implement an array that can be efficiently resized. Add an element to its end in an efficient-on-average manner.

View sample discussion (0 comments)
View problem discussion (0 comments)