1

I am begginner in java and queues.I have one queue which contains only integers. In my code, I am doing operations inside a for loop with a few queues. Is there any way to sort the queue without using another queue? I mean i want to use only the same queue. The queue like this:

Queue q = new Queue(10);
q.enqueue(89);
q.enqueue(17);
q.enqueue(25);
q.enqueue(5);
q.enqueue(39);
q.enqueue(96);

I was able to do it with two queues in the another code. But since it is in a for loop in my code and it is assigned before a queue for loop, I could not use that method.

1 Answer 1

1

If you want a queue with sorting characteristics, then you'd be better off using a PriorityQueue, where you can configure your comparator in the constructor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.