Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a deque as described in challenge 1 (posted below), except base your i

ID: 3707083 • Letter: I

Question

Implement a deque as described in challenge 1 (posted below), except base your implementation on an array. The constructor for the class should accept an integer parameter for the capacity of the deque and create an array of that size. Use a graphical user interface gased on an array of text fields similar to what is shown below. Test your deque class by constructing a deque with capacity 10.

Here is challenge 1 prompt:

Chapter 21, Problem 1PC Bookmark Show all steps: ON Problem Double-Ended Queue A deque (pronounced "deck") is a list-based collection that allows additions and removals to take place at both ends. A deque supports the operations addFront(x), removeFront), addRearfx), RNilow.tdtxar ,'arey , and figu y Wiik: a dixx; il a i nfksinris a cicx1??: trai sio es silings using a doubly-linked list that you code yourself. Demonstrate your class with a graphical user interface that allows users to manipulate the deque by typing appropriate commands in a JTextField component, and see the current state of the deque displayed in a JTextArea component. Consult the documentation for the JTextArea class for methods you can use to display each item in the deque on its own line.

Explanation / Answer

While creating program of DeQueue, you should keep few things in mind. As given in problem statement that size should be given at the time of input. Other one is handling overflow and underflow conditions.

Overflow: Adding element when given array is already fully occupied by elements

Underflow: Trying to remove element when array is already empty.

Class DeQueueExample{

public static main void(String args[]){

//takes input from console

Scanner scan=new Scanner(System.in);

Integer size=scan.nextInt();

//example : add front --> this will add from front, add rear, remove rear

String operation_type=scan.nextLine();

integer num=scan.nextInt();

String inputs[]=operation_type.split(" ");

int[] dq=new int[size];

int front=0;

int rear=size-1;

if(front<rear){

if(inputs[0].equals("add")){

if(inputs[1].equals("front")) { dq[front]=num; front++;}

else dq[rear]=num; rear--;

}

if(inputs[0].equals("remove")){

if(inputs[1].equals("front")) { front--;}

else rear++;

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote