官术网_书友最值得收藏!

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
主站蜘蛛池模板: 昌乐县| 临漳县| 余姚市| 崇明县| 封开县| 闽侯县| 玛多县| 邳州市| 咸阳市| 辽阳市| 新兴县| 崇州市| 永寿县| 罗甸县| 霍城县| 中卫市| 石家庄市| 邓州市| 嵊州市| 肇源县| 鄂托克旗| 杨浦区| 甘肃省| 岑溪市| 四川省| 博兴县| 磐安县| 行唐县| 玉门市| 保康县| 闸北区| 阿克陶县| 拉孜县| 颍上县| 玛曲县| 伊川县| 迁西县| 阳新县| 靖西县| 凉城县| 沅陵县|