Forever Young

「笔记」C++负数下标

如何使用负数下标呢?
让数组前面有东西

int y[100];
int *z = y + 50;

这样的话调用\(z[-50]\)就变成了调用\(y[0]\)

z[-50] = y[0];

然后这样就可以实现调用啦~

其实还有一个更暴力的方法:用\(map\)

\(map\)\(\log n\)\(map\)
\(unordered\_map\)\(O(1)\)\(map\)(到\(c++11\)才会有)

posted @ 2019-10-30 16:33  Loceaner  阅读(2454)  评论(9编辑  收藏  举报