5
\$\begingroup\$

Which data structure should be best used to store a pile of tiles from which a player can pick a random tile?

\$\endgroup\$
  • \$\begingroup\$ We need more information to give a good answer (more...) \$\endgroup\$ – CiscoIPPhone Apr 26 '11 at 11:48
  • \$\begingroup\$ For example, will you be adding tiles to the structure? Will you be removing tiles from the structure? \$\endgroup\$ – CiscoIPPhone Apr 26 '11 at 11:48
3
\$\begingroup\$

I'd suggest any container that has random access (wikipedia), for example a plain array, vector, or deque.

int tiles[100];

or

std::vector<int> tiles;

This will allow you to select a random element without having to step through the container.

I have left a comment asking for more information, if more information is added I'll update this answer.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.