Add a member method to the Queue class shown in attached code in Learning material/week6-7, and this added method will remove and return the second element of this queue. The headline of this function has been given below. public long removeSecond() { // your code here }
class queue:
class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
public long removeSecond() { long second = this.queArray[1]; // Assuming that nItmes holds the size of the queue for (int i = 2; i < this.nItems; i++) { this.queArray[i-1] = this.queArray[i]; } this.nItems--; this.rear--; return second; }
Add a member method to the Queue class shown in attached code in Learning material/week6-7, and...
Add a member method to the Queue class shown in attached code in Learning material/week6-7, and this added method will remove and return the second element of this queue. The headline of this function has been given below. public long removeSecond() { // your code here } class queue: class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems;
Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that one item and no items display properly, no matter where front...
please explain all the steps. I need it ASAP.
i will give u good ratings.
Do in java file Queues are often used to simulate the flow of people, cars, airplanes, transactions, and so on. Write a program that models checkout lines at a supermarket, using the Queue class from the queue.java program (Listing 4.4). Several lines of customers should be displayed; you can use the display, insertſ), and remove() method. You can add a new customer by pressing a...
Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...
CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...
AQueue.java
class AQueue implements Queue {
private E queueArray[]; // Array holding queue elements
private static final int DEFAULT_SIZE = 10;
private int maxSize; // Maximum size of queue
private int front; // Index of front element
private int rear; // Index of rear element
// Constructors
@SuppressWarnings("unchecked") // Generic array allocation
AQueue(int size) {
//BUG #1: maxSize = size
maxSize = size+1; // One extra space is allocated
rear = 0; front = 1;
queueArray = (E[])new Object[maxSize]; //...
public class CharNode{ private CharNode link; private char info; public CharNode(char info) { this.info = info; this.link = null; } public CharNode(char c, CharNode link) { this.info = info; this.link = link; } public CharNode getLink() { return link; } public void setLink(CharNode link) { this.link = link; } public char getInfo() { return info; } public void setInfo(char info) { this.info = info; } } //Remember Queue is a first-in-first-out data structure public class CharQueue { // front is...
Complete the following code. /** Insert an item at the rear of the queue. post: item is added to the rear of the queue. @param item The element to add @return true (always successful) */ public boolean ____(E item) { // Check for empty queue. if (front == null) { rear = new Node<E>(item); front = rear; } else { // Allocate a new node at end, store item in it, and // link it to old end of queue....
Java/Queues ** Task: Write a JUnit test that shows a failure in some part of the ADT -----ArrayQueue.java------- public class ArrayQueue { private static final int INITIAL_CAPACITY = 2; // to permit easier testing private Object[] contents; private int front, rear; /** * Create an empty queue with an initial capacity. */ public ArrayQueue() { contents = new Object[INITIAL_CAPACITY]; } /** * Add an element to...
e. public class Queue { // Uses the correct Stack class from ME2
Ex 19 private Stack mStack; public Queue() { setStack(new Stack());
} public Queue enqueue(E pData) { getStack().push(pData); return
this; } public E dequeue() { return getStack().pop(); } public E
peek() { return getStack.peek(); } private Stack getStack() {
return mStack; } private void setStack(Stack pStack) { mStack =
pStack; } }
f. public class Queue extends Stack { // Uses the correct Stack
class from ME2 Ex...