Is it bad practice to use multi-dimensional arrays

2020-05-31 08:53发布

Some programmers seem to violently hate them, while others seem to think they're fine. I know that anything that can be done to a multi-dimensional array can also be done to a regular array, so they're functionally equivalent. Is it bad practice to use multi-dimensional arrays, or does it not matter?

9条回答
你好瞎i
2楼-- · 2020-05-31 09:40

If multidimensional index computation bugs you, std::valarray with std::slice is the standard abstraction.

查看更多
小情绪 Triste *
3楼-- · 2020-05-31 09:41

How would you implement my favorite algorithm without it?

查看更多
\"骚年 ilove
4楼-- · 2020-05-31 09:46

I know that anything that can be done to a multi-dimensional array can also be done to a regular array

I do not think that's entirely accurate. We'll need an array of pointers to store something as basic as a list of names and then sorting it. Or pointers to pointers to store a variable length string and then a list of such strings. As the original questions mentions only arrays per se, can't see how problems like these can be done with equal ease in a regular array. Please consider not just storing the strings in a 1-D array (using some sort of separator maybe) but also performing operations such as sorting.

查看更多
登录 后发表回答