hi all programmer
i have this question : Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a code fragment that uses only D and Q (and no other variables) and results in D storing the elements in the order (1,2,3,5,4,6,7,8). and I try to use this code: ArrayDeque<Integer> D = new ArrayDeque<>(); D.addAll(List.of(1, 2, 3, 4, 5, 6, 7, 8)); Queue<Integer> Q = new ArrayDeque<>(); while (!D.isEmpty()) { Q.offer(D.poll()); if (!D.isEmpty()) { D.offer(D.poll()); } } System.out.println("D: " + D); System.out.println("Q: " + Q); I want swapped just between 4 and 5 but I get wrong output why? please who can help me?