import java.lang.Math;
Queue<Object> queue = new LinkedList<>();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
queue.add(7);
queue.add(8);
queue.add(9);
System.out.println("Ordered Queue");
System.out.println(queue);
ArrayList arr = new ArrayList(queue);
Queue<Object> queue2 = new LinkedList<>();
for (int i = arr.size(); i > 0; i--) {
int rand = (int) (Math.random() * i) + 1;
queue2.add(arr.get(rand-1));
arr.remove(rand-1);
}
System.out.println("Shuffled Queue");
System.out.println(queue2);
import java.lang.Math;
import java.util.*;
Queue<Object> queue = new LinkedList<>();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
queue.add(7);
queue.add(8);
queue.add(9);
ArrayList arr = new ArrayList(queue);
System.out.println("Queue");
while (queue.size() > 0) {
System.out.print(queue.remove());
System.out.print(' ');
}
System.out.println();
Stack<Object> stack = new Stack<>();
for (Object num: arr) {
stack.push(num);
}
System.out.println("Stack");
while (stack.size() > 0) {
System.out.print(stack.pop());
System.out.print(' ');
}