A vector would be an option.
rubberman
Posting Maven
2,571 posts since Mar 2010
Reputation Points: 365
Solved Threads: 305
Skill Endorsements: 51
I think that you should make a distinction between the question's ID and its number in the test. I would make the ID constant throughout the life of the question, but allow the number to change. You could do this by having a GenerateQuiz (or similar) function that goes through all the questions and a assembles them into a quiz. It's not until this function is called that a question needs to be alloacted its number. So, you could just store all the questions in a std::vector and then use the GenerateQuiz function to assemble the questions and add the numbers.
This method would allow the further advantage that you could assemble different quizes from the same question set. For example, your Question class might have a level attribute. You could then let the GenerateQuiz method take a parameter (an enum or something) that would let you assemble different types of quiz:
Quiz easyQuiz = GenerateQuiz( questions, grade1 );
Quiz hardQuiz = GenerateQuiz( questions, grade3 );
where, grade1 and grade3 are enum values that tells the method that only questions of that level should be in the test.
Have fun :)
ravenous
Practically a Master Poster
681 posts since Jul 2005
Reputation Points: 286
Solved Threads: 111
Skill Endorsements: 8
Indeed, deleting from a memory-contiguous-like container (such as a vector, or an array), requires a bit of time, because the system has to shift all the elements to get the desired result, but, it has some advantages. I see you mention a lot that you want to access the quesitons by their given id. Vectors for example, have a direct access to its members, as opposed to linked lists.
If you think you'll be doing a lot of deleting from the middle, than I would suggest looking over linked lists, since their delete and insert time are rather closed to O(1). As I said before, it's downside is the element access. You can't directly access elements from your liked-list, you have to parse the entire list, till you find the desired element.
Regarding your problem, I would suggest using std::vector since it's easier to handle, and with small amount of information (300-400 question), the deletion wouldn't be a problem. For deleting elements you should look into std::vector's function:
erase.
Lucaci Andrew
Practically a Master Poster
649 posts since Jan 2012
Reputation Points: 91
Solved Threads: 91
Skill Endorsements: 11
Question Answered as of 2 Months Ago by
ravenous,
rubberman
and
Lucaci Andrew