EBK COMPUTER SCIENCE: AN OVERVIEW
EBK COMPUTER SCIENCE: AN OVERVIEW
12th Edition
ISBN: 8220102744196
Author: BRYLOW
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 8, Problem 51CRP

Explanation of Solution

Modified interface for Queue and its code:

The modified interface for queue and its corresponding queue of integer’s implementation in java and C# is shown below:

//Interface for QueueType

interface QueueType

{

  //Function declaration to add a value to queue

  public void insertQueue(int item);

  //Function declaration to remove a value from queue

  public int removeQueue();

  //Function declaration for check if queue is empty

  public boolean isEmpty();

  //Function declaration for check if queue is Full

  public boolean isFull();

}

//Class for QueueOfInteger

class QueueOfIntegers implements QueueType

{

  //Initializes the size of queue

  private int size = 20;

  //Create an array for QueueEntries

  private int[] QueueEntries = new int[size];

/* Declare the variable for front of queue, rear of queue and length of queue*/

  private int frontQueue, rearQueue, queueLength;

  //Function definition for insert Queue

  public void insertQueue(int NewEntry)

  {

    //If the rearQueue is equal to '-1', then

    if (rearQueue == -1)

    {

      //Assign the frontQueue to "0"

      frontQueue = 0;

      //Assign the rearQueue to "0"

      rearQueue = 0;

/* Assign the Array of QueueEntries to NewEntry */

      QueueEntries[rearQueue] = NewEntry;

    }

/* If the rearQueue+1 is greater than or equal to "size" */

    else if (rearQueue + 1 >= size)

System.out.println("Queue Overflow Exception");

    //If the rearQueue+1 is less than "size"

    else if ( rearQueue + 1 < size)

/* Assign the Array of QueueEntries to NewEntry */

      QueueEntries[++rearQueue] = NewEntry;  

      //Increment the queue length

      queueLength++ ;   

  }

  //Function definition for remove a value from queue

  public int removeQueue()

  {

    //If the queue is not empty, then

    if(!isEmpty())

      //Decrement the length of queue

      queueLength--;

/* Assign the front of queue entries to element */

      int element = QueueEntries[front];

      //If the queue front is equal to rear

      if(frontQueue == rearQueue)

      {

/* Assign the value to front and rear of queue */

        frontQueue = -1;

        rear...

Blurred answer
Students have asked these similar questions
A Stack is a data structure for storing a list of elements in a LIFO (last in, first out) fashion. Design a class called Stack with three methods. void Push(object obj)object Pop()void Clear() We should be able to use this stack class as follows:var stack = new Stack();stack.Push(1);stack.Push(2);stack.Push(3);Console.WriteLine(stack.Pop());Console.WriteLine(stack.Pop());Console.WriteLine(stack.Pop());   The output should be 3, 2, 1
**Use the Stack interface to implement the LinkedStack.java class. Stack.java public interface Stack<E> {/*** Push an element onto the stack.** @param element, a value to be pushed on the stack*/public void push(E element);/*** Pop the top element off the stack.*/public E pop();/*** Return the top element on the stack.*/public E top();/*** Return True if the stack contains no elements.** @return true if there are no elements in the stack*/public boolean isEmpty();} ***In LinkedStack.java, change only The methods with empty bodies Do not use a sentinel node. In this implementation you use an inner class That is, a class that is declared inside of another class. The Node class isn't needed by any other class, so it is declared as a private class inside the LinkedStack class. The Node class has two fields: element and next. Things to note in the class LinkedStack: The EmptyStackExceptionis being used, same as in the ArrayStack. The class StringJoineris imported for use in the…
Java Consider the following class definition for an array-based stack implementation:pubic class Stack {   private int[] m_array;   private int m_index;      public Stack(int cap) {      m_array = new int[cap];      m_index = 0;   }    public void push(int v) {      if (m_index == m_array.length)         throw new RuntimeException("push attempted on a full stack");      else {         m_array[m_index] = v;         m_index++;      }   }} Follow the steps below to create a class SpecialStack with required instance variables and methods.a.    Make sure that the SpecialStack class inherits from Stack. b.    Declare two private instance variables: a boolean variable m_multiply, and an int variable m_number.c.    Create a constructor that takes three parameters: an int cap, a boolean multiply, and an int number.d.    The constructor should call the constructor of the super class and initialize the instance variables properly.e.    Override the push method so it verifies if m_multiply is…

Chapter 8 Solutions

EBK COMPUTER SCIENCE: AN OVERVIEW

Ch. 8.3 - Prob. 3QECh. 8.3 - Prob. 4QECh. 8.3 - Modify the function in Figure 8.19 so that it...Ch. 8.3 - Prob. 7QECh. 8.3 - Prob. 8QECh. 8.3 - Draw a diagram representing how the tree below...Ch. 8.4 - Prob. 1QECh. 8.4 - Prob. 2QECh. 8.4 - Prob. 3QECh. 8.4 - Prob. 4QECh. 8.5 - Prob. 1QECh. 8.5 - Prob. 3QECh. 8.5 - Prob. 4QECh. 8.6 - In what ways are abstract data types and classes...Ch. 8.6 - What is the difference between a class and an...Ch. 8.6 - Prob. 3QECh. 8.7 - Suppose the Vole machine language (Appendix C) has...Ch. 8.7 - Prob. 2QECh. 8.7 - Using the extensions described at the end of this...Ch. 8.7 - In the chapter, we introduced a machine...Ch. 8 - Prob. 1CRPCh. 8 - Prob. 2CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 4CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 6CRPCh. 8 - Prob. 7CRPCh. 8 - Prob. 8CRPCh. 8 - Prob. 9CRPCh. 8 - Prob. 10CRPCh. 8 - Prob. 11CRPCh. 8 - Prob. 12CRPCh. 8 - Prob. 13CRPCh. 8 - Prob. 14CRPCh. 8 - Prob. 15CRPCh. 8 - Prob. 16CRPCh. 8 - Prob. 17CRPCh. 8 - Prob. 18CRPCh. 8 - Design a function to compare the contents of two...Ch. 8 - (Asterisked problems are associated with optional...Ch. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 22CRPCh. 8 - Prob. 23CRPCh. 8 - Prob. 24CRPCh. 8 - (Asterisked problems are associated with optional...Ch. 8 - Prob. 26CRPCh. 8 - Prob. 27CRPCh. 8 - Prob. 28CRPCh. 8 - Prob. 29CRPCh. 8 - Prob. 30CRPCh. 8 - Design a nonrecursive algorithm to replace the...Ch. 8 - Prob. 32CRPCh. 8 - Prob. 33CRPCh. 8 - Prob. 34CRPCh. 8 - Draw a diagram showing how the binary tree below...Ch. 8 - Prob. 36CRPCh. 8 - Prob. 37CRPCh. 8 - Prob. 38CRPCh. 8 - Prob. 39CRPCh. 8 - Prob. 40CRPCh. 8 - Modify the function in Figure 8.24 print the list...Ch. 8 - Prob. 42CRPCh. 8 - Prob. 43CRPCh. 8 - Prob. 44CRPCh. 8 - Prob. 45CRPCh. 8 - Prob. 46CRPCh. 8 - Using pseudocode similar to the Java class syntax...Ch. 8 - Prob. 48CRPCh. 8 - Identify the data structures and procedures that...Ch. 8 - Prob. 51CRPCh. 8 - In what way is a class more general than a...Ch. 8 - Prob. 53CRPCh. 8 - Prob. 54CRPCh. 8 - Prob. 55CRPCh. 8 - Prob. 1SICh. 8 - Prob. 2SICh. 8 - In many application programs, the size to which a...Ch. 8 - Prob. 4SICh. 8 - Prob. 5SICh. 8 - Prob. 6SICh. 8 - Prob. 7SICh. 8 - Prob. 8SI
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning