Simple Array
Problem Description: We wish to design a simple array whose size can be determined at run-time, its multi-dimensional equivalent can be passed to functions with ease.
Premises: Generic algorithms than require using 2 or more dimensional containers can be a pain to write if we rely solely on the the default C-style array provided by C++.
The problem I have with that code is that I have to explicitly define the column size of the array X. I want to be able to write something like this
or something like this
Using a vector of vector can cause memory fragmentation in some cases, hence I opt for a simple array, like the basic C-style array. Here I present a simple 1, 2, 3 dimensional array container whose size can be passed at run time.
I want my proposed array to be as simple as possible so I provide only access operator.
Solution:
The code is shown below:
Example:
The below shows an example of its use. Our simple array is even more versatile in that we can also use as 1d array. But care should be taken.
when called with the input file
We get
Note: This simple array would be my default container for all my algorithmic posts.