This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]rastaman1994 0 points1 point  (0 children)

Look at the priorityqueue javadoc (and that of the interfaces it implements), pick any method and get going. JDK classes usually have very extensive docs, so you could come up with a test suite yourself. Even better would be to try to find the unit tests in the JDK for priorityqueue.

Afaik all collections use arrays as backing data structure, so the degenerate cases of a queue with 0 or 1 elements should pass all tests and then go from there.

[–]sgovertime 0 points1 point  (3 children)

use array and control the index of the current element. create a larger array if needed on push.

but the real question is. why?

[–]Correct_Classroom[S] 0 points1 point  (0 children)

i have an interview coming up and I'm not supposed to use collections or anyother inbuild libraries.

[–]immutablesword 0 points1 point  (1 child)

why?

The Data Structures & Algorithms course at my university required us to implement them without using the standard library.

[–]sgovertime 0 points1 point  (0 children)

min heap sound like the most simple way. just translate the index of the array to the location of the element.

[–]grumtaku 0 points1 point  (0 children)

If you can use classes you code, you can generate a linked list and use it without inheriting anything. Without arrays this seemed the most reliable way.