Question

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;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Removing second element from Queue in Java:

import java.util.*; public class Qlist { public static void main(String[] args) throws IllegalStateException { // create object of Queue Queue<Integer> Q = new LinkedList<Integer>(); // Add numbers to end of Queue Q.add(7855642); Q.add(35658786); Q.add(5278367); Q.add(74381793); System.out.println("Queue before removing second element:"); // print queue System.out.println("Queue: " + Q); // print head and deletes the head Q.remove(35658786); System.out.println("Queue after removing second element:"); System.out.println("Queue: " + Q); } } 
Add a comment
Know the answer?
Add Answer to:
Add a member method to the Queue class shown in attached code in Learning material/week6-7, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

    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...

    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 */};...

    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....

    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...

    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;...

    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...

    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...

    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 t...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT