How can I create an array such that I could access the elements a[1000000]
, a[1]
and a[2]
and not even using the size of 1000000?
If possible please provide the answer in C++
.
How can I create an array such that I could access the elements a[1000000]
, a[1]
and a[2]
and not even using the size of 1000000?
If possible please provide the answer in C++
.
Use std::unordered_map<>
.
enum { N = 9 };
int arr[N] = { 0 };
std::unordered_map<int, int> m;
for (int i = 0; i < N; i++)
{
++m[arr[i]];
}