- 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
推薦閱讀
- 極簡算法史:從數學到機器的故事
- Power Up Your PowToon Studio Project
- x86匯編語言:從實模式到保護模式(第2版)
- Apex Design Patterns
- RISC-V體系結構編程與實踐(第2版)
- C++從入門到精通(第5版)
- Learning Concurrency in Kotlin
- Webpack實戰:入門、進階與調優
- 用案例學Java Web整合開發
- 深入淺出Go語言編程
- UML2面向對象分析與設計(第2版)
- Drupal 8 Development:Beginner's Guide(Second Edition)
- Java自然語言處理(原書第2版)
- 面向物聯網的Android應用開發與實踐
- SQL Server 2012數據庫管理與開發(慕課版)