|
Vector (or std::vector) is a C++ implementation of the dynamic array data structure. Its interface emulates the behavior of a C array (i.e., capable of fast random access) but with the additional ability to automatically resize itself when inserting or erasing an object. C++ (pronounced see plus plus, IPA: ) is a general-purpose, programming language with high-level and low-level capabilities. ...
A dynamic array, growable array, resizable array, dynamic table, or array list is a data structure, an array which is automatically expanded to accommodate new objects if filled beyond its current size. ...
A binary tree, a simple type of branching linked data structure. ...
C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
This article does not cite any references or sources. ...
In computer science, random access is the ability to access a random element of a group in equal time. ...
Vector is a template class that is a part of the C++ Standard Template Library. It can store any type, but is limited to storing only one type per instance. It provides a standard set of methods for accessing elements, adding elements to the start or end, deleting elements and finding how many elements are stored. In computer programming, templates are a feature of the C++ programming language that allow code to be written without consideration of the data type with which it will eventually be used. ...
The Standard Template Library (STL) is a software library included in the C++ Standard Library. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
Used mainly in object-oriented programming, the term method refers to a piece of code that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods). ...
Comparison with Arrays
In C++, arrays are contiguous pieces of memory. They are somewhat like blocks aligned together, each block is then given a number, and to look at the contents of each block one only has to supply the number of the block. All the elements of an array must be of the same type. This article does not cite any references or sources. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
A vector is similar to an array but with extended functionality. One of the features of a vector is that if you use the at() function, an exception will be thrown if you try to access an element that doesn't exist. A vector is a template class, a generic array of whatever type you want it to be. This gives vectors a great deal of flexibility, as they can be used as an array of anything. For instance, you can even have a vector of vectors. Vectors automatically detect out of bounds errors (see Bounds checking) and they are very fast for random access. Vectors also have a number of useful functions which can tell you certain properties of the vector. For a full description of each function see functions further down the page. In computer programming, templates are a feature of the C++ programming language that allow code to be written without consideration of the data type with which it will eventually be used. ...
In object-oriented programming, a class is a programming language construct that is used to group related instance variables and methods. ...
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact. ...
In computer programming, bounds checking is the name given to any method of detecting whether or not an index given lies within the limits of an array. ...
In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. ...
Usage A vector is included into a C++ program by including the header <vector>. <vector.h> should not be used as it is non-standard. The implementation that GCC provides has the old headers, which give a compiler warning when an attempt is made to use them. The GNU Compiler Collection (usually shortened to GCC) is a set of programming language compilers produced by the GNU Project. ...
A vector is initialised using: std::vector<type> instance; where "type" is the type you want to store in the vector and instance is the name of the variable that you refer to the new vector with. In computer science and mathematics, a variable (IPA pronunciation: ) (sometimes called a pronumeral) is a symbolic representation denoting a quantity or expression. ...
"Type" can be a primitive or any user defined class or struct. In computer science, primitive types, as distinct from composite types - are datatypes provided by a programming language as basic building blocks. ...
Functions The vector class models the Container concept, which means it has begin(), end(), size(), max_size(), empty(), and swap() methods. In generic programming, a concept is a description of supported operations on a type, including syntax and semantics. ...
- vector::front - Returns reference to first element of vector.
- vector::back - Returns reference to last element of vector.
- vector::push_back - Appends (inserts) an element to the end of a vector, allocating memory for it if necessary. Amortized O(1) time.
- vector::pop_back - Erases the last element of the vector, possibly reducing capacity. Amortized O(1) time.
- vector::size - Returns number of elements in the vector.
- vector::begin - Returns an iterator to start traversal of the vector.
- vector::end - Returns an iterator for the last element of the vector.
- vector::empty - Returns true if vector has no elements.
- vector::insert - Inserts elements into a vector (single & range), shifts later elements up. Inefficient.
- vector::erase - Deletes elements from a vector (single & range), shifts later elements down. Inefficient.
- vector::clear - Erases all of the elements.
- vector::resize - Changes the vector size.
- vector::capacity - Returns current capacity of vector.
... and many more not listed here In computational complexity theory, amortized analysis is the time per operation averaged over a worst_case sequence of operations. ...
In computational complexity theory, amortized analysis is the time per operation averaged over a worst_case sequence of operations. ...
External links |