I\'m doing some exam (Java-based algorithmics) revision and have been given the
ID: 648134 • Letter: I
Question
I'm doing some exam (Java-based algorithmics) revision and have been given the question:
Describe how you might extend your implementation [of a queue using a circular array] to support the expansion of the Queue to allow it to store more data items.
The Queue started off implemented as an array with a fixed maximum size. I've got two current answers to this, but I'm not sure either are correct:
Implement the Queue using the Java Vector class as the underlying array structure. The Vector class is similar to arrays, but a Vector can be resized at any time whereas an array's size is fixed when the array is created.
Copy all entries into a larger array.
Is there anything obvious I'm missing?
Explanation / Answer
As explained by Guillaume13, Vector is deprecated and therefore the usage should be discouraged. There is the ArrayList class though, which basically does the same but is more up to date in the Java world.
Considering your the actual question, I think both answers are more or less equally good, as the term "extend" can be interpreted quite vast. Both design ideas would work and do their job, but not perfect (as already pointed out by Gilles), therefore they are, interpreting the task, as to program a flexible queue, not perfect.
Depending if you have to keep an "true" array (which is by design not flexible) the second might be the more fitting choice, though.
In my opinion a lisp-like list, where you just work with cells storing a value and a pointer to the next cell, would be the best answer if you are allowed to discard the old implementation. But I am not sure if such a revolutionizing design, considering your starting point, would still be within the reach of of the question.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.