- Mastering C++ Programming
- Jeganathan Swaminathan
- 183字
- 2021-07-02 18:28:49
Commonly used APIs in an array
The following table shows some commonly used array APIs:

The array container supports random access; hence, given an index, the array container can fetch a value with a runtime complexity of O(1) or constant time.
The array container elements can be accessed in a reverse fashion using the reverse iterator:
#include <iostream>
#include <array>
using namespace std;
int main () {
array<int, 6> a;
int size = a.size();
for (int index=0; index < size; ++index)
a[index] = (index+1) * 100;
cout << "\nPrint values in original order ..." << endl;
auto pos = a.begin();
while ( pos != a.end() )
cout << *pos++ << "\t";
cout << endl;
cout << "\nPrint values in reverse order ..." << endl;
auto rpos = a.rbegin();
while ( rpos != a.rend() )
cout << *rpos++ << "\t";
cout << endl;
return 0;
}
We will use the following command to get the output:
./a.out
The output is as follows:
Print values in original order ...
100 200 300 400 500 600
Print values in reverse order ...
600 500 400 300 200 100
推薦閱讀
- Oracle從入門到精通(第3版)
- AngularJS Testing Cookbook
- Instant Apache Stanbol
- Vue.js前端開發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- Visual Basic程序設(shè)計(jì)(第3版):學(xué)習(xí)指導(dǎo)與練習(xí)
- Python Web數(shù)據(jù)分析可視化:基于Django框架的開發(fā)實(shí)戰(zhàn)
- C語言程序設(shè)計(jì)
- Learning R for Geospatial Analysis
- SwiftUI極簡(jiǎn)開發(fā)
- ASP.NET開發(fā)寶典
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程(第二版)
- Building a Media Center with Raspberry Pi
- Isomorphic Go
- Mastering Unity 2017 Game Development with C#(Second Edition)
- 深度剖析ApacheDubbo核心技術(shù)內(nèi)幕