矢量或列表--->困惑 [英] vector or list ---> confused

查看:85
本文介绍了矢量或列表--->困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我知道矢量和列表是什么?


我有这个场景,我想知道哪个是最好的使用。


我有一个名为分子的类。一个分子可以容纳的最大原子数是72.原子的数量取决于分子的类型,它可以是4或10或1或50等等......直到maxatoms。


因此,由于最大原子数是固定的,即72,而对于当前分子,如果原子数仅为4,则有68个空位空。

大的浪费空间

我也想随机访问原子,测试某些条件。

目前我使用 vector< molecule> 但我认为使用vector可以帮助我随机访问原子但会占用更多内存。你不觉得吗?


那么你认为什么才是最好的矢量/列表对于上面讨论的场景。


提前谢谢

Hi guys,
I know what a vector and a list is?

I have this scenario and I want to know which will be best to use.

I have a class called "molecule". The maximum number of atoms a molecule can hold is 72. The number of atoms vary depending on the type of molecule, it can be 4 or 10 or 1 or 50 etc etc...upto maxatoms.

Hence, since the maximum number of atoms is fixed i.e 72, and for current molecule if the number of atoms is only 4, there are 68 vacant space empty.
A big "waste of space".
Also I want to randomly access the atoms, to test certain conditions.
Currently I use vector<molecule> but I think using vector can help me randomly access the atoms but eats up more memory. Dont you think?

So what do you think can be best "vector/list" for above discussed scenario.

Thanks in advance

推荐答案


另外我想随机访问原子,以测试某些条件。
Also I want to randomly access the atoms, to test certain conditions.



这里的神奇短语是随机访问;所以使用矢量。


亲切的问候,


Jos

The magic phrase here is "random access"; so use a vector.

kind regards,

Jos



这里的神奇短语是随机访问;所以请使用矢量。


亲切的问候,


Jos
The magic phrase here is "random access"; so use a vector.

kind regards,

Jos



不要你认为在上面的场景中使用向量是一个很大的内存浪费虽然有助于我随机访问要素?


谢谢

Dont you think using a vector in the above scenario is a big waste of memory though is helps me to "randomly access" the elements?

Thanks



你不认为在上面的场景中使用向量是一个很大的浪费虽然内存有助于我随机访问要素?


谢谢
Dont you think using a vector in the above scenario is a big waste of memory though is helps me to "randomly access" the elements?

Thanks



不,矢量不包含固定数量的元素,例如如果你有一个包含68个元素的
向量,那么向量将占用比只包含2个元素的

向量更多的内存;向量不是固定大小的数组。


亲切的问候,


Jos

Nope, a vector doesn''t contain a fixed number of elements, e.g. if you have a
vector containing 68 elements the vector will take up more memory than a
vector containing just 2 elements; vectors aren''t fixed size arrays.

kind regards,

Jos


这篇关于矢量或列表---&gt;困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆