0

I have a queue (Q) = 1,4,6,9,2,7,5 which I got by merging two queues. I want to reverse this queue as 5,7,2,9,6,4,1 using reverse method in Java. This is what I have

 List<Integer> myQueue = new ArrayList<Integer>(Arrays.asList(1, 4, 6, 9, 2, 7, 5)); 
Marlon Abeykoon
  • 11,927
  • 4
  • 54
  • 75
  • 3
    show an attempt, no one will do this for you. How about pushing everything onto a stack and then popping the stack into a new queue? – turbo Jan 06 '14 at 19:03
  • 3
    What code have you written to solve this problem? We'll gladly answer and critique your coding questions but all we ask is that you show us what you first attempted yourself. – wheaties Jan 06 '14 at 19:03
  • possible duplicate of [java: reverse list](http://stackoverflow.com/questions/3962766/java-reverse-list) – lebolo Jan 06 '14 at 19:08
  • Please help me reopen this . I have updated the Question with the code I have. Due to this they have blocked me from asking questions in Stackoverflow. I will not post such questions again. Thanx – Marlon Abeykoon Apr 16 '14 at 10:23

1 Answers1

1

This one is quite simple. First line creates the queue. Second shows it to you. Third reverses it. Fourth prints it out showing that is was reversed.

    List<Integer> queue = new ArrayList<Integer>(Arrays.asList(1, 4, 6, 9, 2, 7, 5));
    System.out.println(queue);
    Collections.reverse(queue);
    System.out.println(queue);

The output of which is:

    [1, 4, 6, 9, 2, 7, 5]
    [5, 7, 2, 9, 6, 4, 1]
David S.
  • 6,567
  • 1
  • 25
  • 45