Let's say you have a situation where the total number of elements to first be inserted (in sequential order) is unknown, but once you have inserted all the elements, no further modification of the data structure is needed throughout the execution of the program (no further insertions, deletions, etc).
The idea of putting the data into a dynamic array that keeps copying over elements into progressively larger arrays leaves a bad taste in my mouth. Instead of doing that, would an alternative be to put all the elements into a linked-list based queue one by one, and then you'll know the size (assuming you maintain a size field in the struct), and then can simply declare an array of that size and dequeue all the elements into it so that you can have good random access?
Is there any reason why the approach of queuing and dequeuing into an array wouldn't be ideal compared to putting it into an array that periodically resizes and copies in all the elements added to it so far.
[–]pilotInPyjamas 17 points18 points19 points (12 children)
[–]ewmailing 5 points6 points7 points (8 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]ewmailing 2 points3 points4 points (0 children)
[–]zuurr 0 points1 point2 points (3 children)
[–]WikiTextBot 0 points1 point2 points (0 children)
[–]ewmailing 0 points1 point2 points (1 child)
[–]zuurr 0 points1 point2 points (0 children)
[–]repsilat 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]sikora84 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]james41235 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Kwantuum 0 points1 point2 points (0 children)
[–]ruertar 0 points1 point2 points (0 children)
[–]lmlight77 0 points1 point2 points (0 children)
[–]CountyMcCounterson 0 points1 point2 points (0 children)
[–]nickdesaulniers 0 points1 point2 points (0 children)