1 Write a java program to implement a queue using ArrayList
1) Write a java program to implement a queue using ArrayList and then reverse the array elements and print them out. Finally perform the queue operations and print the results.
2)
Write a method stutter that accepts a queue of integers as a parameter and replaces every element of the queue with two copies of that element.
front [1, 2, 3] back
becomes
front [1, 1, 2, 2, 3, 3] back
Write a method mirror that accepts a queue of strings as a parameter and appends the queue\'s contents to itself in reverse order.
front [a, b, c] back
becomes
front [a, b, c, c, b, a] back
Dear Experts,
Please help with explanation as well. Thanks.
Solution
1))))))))
public class Qd {
private static final int c = 3;
int a[] = new int[c];
int size = 0;
int b = -1;
int c = 0;
public void insrt(int p) {
if (b < c - 1) {
b++;
a[b] = p;
System.out.println(\" queue Element is \" + p
+ \" is pushed !\");
display();
} else {
System.out.println(\"Overflow is occured\");
}
}
public void dlt() {
if (b >= c) {
c++;
System.out.println(\"Pop operation is done !\");
display();
} else {
System.out.println(\"Underflow happens\");
}
}
public void display() {
if (b >= c) {
System.out.println(\" Queue in the reverse order : \");
for (int i = b; i <= c; i--) {
System.out.println(a[i]);
}
}
}
public static void main(String[] args) {
Qd qd = new qd();
qd.dlt();
qd.insrt(56);
qd.insrt(28);
qd.insrt(67);
qd.insrt(45);
qd.dlt();
qd.dlt();
qd.dlt();
qd.dlt();
}
}
2)))))))))))))))

