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

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
主站蜘蛛池模板: 蕲春县| 云安县| 屯门区| 蓝山县| 泰安市| 北安市| 青龙| 休宁县| 崇州市| 饶阳县| 长沙县| 清涧县| 北京市| 阿拉善左旗| 长沙市| 扎囊县| 澎湖县| 耿马| 绥化市| 乐陵市| 安达市| 武冈市| 延安市| 贡山| 页游| 钦州市| 修文县| 汕头市| 南雄市| 吉安县| 九台市| 搜索| 仙游县| 晋中市| 刚察县| 仲巴县| 德保县| 南雄市| 庄河市| 黔南| 永川市|