Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code For Deque Implementation in Java Code For Deque Implementation in Java import java.util.Arrays; public class AmplifireArrayDeque { static final int MAX = 10; int[]

Code For Deque Implementation in Java

Code For Deque Implementation in Java import java.util.Arrays; public class AmplifireArrayDeque { static final int MAX = 10; int[] array = new int[10]; int head = -1; int tail = 0; int size; public AmplifireArrayDeque(int size) { this.size = size; } boolean isMaxCapacity() { if (this.head == 0 && this.tail == this.size - 1) { return true; } else { return this.head == this.tail + 1; } } boolean isEmpty() { return this.head == -1; } void addToFront(int val) { if (this.isMaxCapacity()) { System.out.println("Overflow"); } else { if (this.head == -1) { this.head = 0; this.tail = 0; } else if (this.head == 0) { this.head = this.size - 1; } else { --this.head; } this.arrary[this.head] = val; } } void addToEnd(int val) { if (this.isMaxCapacity()) { System.out.println("Overflow"); } else { if (this.head == -1) { this.head = 0; this.tail = 0; } else if (this.tail == this.size - 1) { this.tail = 0; } else { ++this.tail; } this.arrary[this.tail] = val; } } void delFront() { if (this.isEmpty()) { System.out.println("Queue Underflow "); } else { if (this.head == this.tail) { this.head = -1; this.tail = -1; } else if (this.head == this.size - 1) { this.head = 0; } else { ++this.head; } } } void delEnd() { if (this.isEmpty()) { System.out.println(" Underflow"); } else { if (this.head == this.tail) { this.head = -1; this.tail = -1; } else if (this.tail == 0) { this.tail = this.size - 1; } else { --this.tail; } } } //Note: Explain The "getFirst", "getLast", and "public String toString()" section int getFirst() { if (this.isEmpty()) { System.out.println(" Underflow"); return -1; } else { return this.arrary[this.head]; } } int getLast() { if (!this.isEmpty() && this.tail >= 0) { return this.arrary[this.tail]; } else { System.out.println(" Underflow "); return -1; } } public String toString() { return "arrary=" + Arrays.toString(this.arrary) + " "; } } 

Assist In Explaining the "getFirst", "getLast", and "public String toString()" section in the code



Step by Step Solution

There are 3 Steps involved in it

Step: 1

Lets break down and explain the getFirst getLast and public String toString sections in the provided ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Programming questions

Question

Explain why it is not wise to accept a null hypothesis.

Answered: 1 week ago