I want to print the arrays in a queue but in ascending, numerical order.
For instance, queue contains
{3, 5},
{4, 5},
{0, 4},
{3, 4},
{4, 6}
How would I make it print as follows?
{0, 4},
{3, 4},
{3, 5},
{4, 5},
{4, 6}
I also checked, but I can't seem to find a way to push an array back into the queue from like the front?
I would appreciate any tips or help.
This is what I tried, but it doesn't work:
while (queue.size() > 0) {
int[] current = queue.remove();
int[] current1 = queue.peek();
if (queue.size()!=0) {
if (current[0]>current1[0]) {
int[] holdarr = current;
current = queue.remove();
queue.add(holdarr);
} else if (current[0] == current1[0] & current[1]>current1[1]) {
int[] holdarr = current;
current = queue.remove();
queue.add(holdarr);
}
}
System.out.println(current[0] + ", " + current[1]);
queue?