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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.