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...
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- Write a program in c or c++ to implement a Stack using array. In order to implement the stack, programfor following stack operations has to be written: • void push(int): to insert data onto the stack.• Int pop(): to remove and return the last inserted element from the stack.• Int top(): Returns the last inserted element without removing it.• int Size(): Returns the number of elements stored in the stack.• int IsEmptyStack(): Indicates whether any elements are stored in the stack or not.• int IsFullStack(): Indicates whether the stack is full or not.arrow_forwardTRUE or FALSE? Answer the following question and state the reason why: In a dynamic stack, the node that was popped is deleted. In a dynamic stack, the pointer top stays at the head after push operation. STL function top returns a reference to element at the top of the stack. STL empty function will yield a value of true if the stack has elements.arrow_forwardThere is a data structure called a drop-out stack that behaves likea stack in every respect except that if the stack size is n, whenthe n + 1 element is pushed, the first element is lost. Implement adrop-out stack using an array. (Hint: A circular array implementation would make sense.)arrow_forward
- One linear structure could be more applicable than another. (A) Can a Stack be used to implement a Queue? How complicated are the Queue operations individually? (b) Can a Stack be implemented using a Queue? What level of complexity do the different Stack techniques have?arrow_forwardImplementing a Stack ADT using a linked solution. The implementations are linked Nodes. class Node: def __init__(self, data, node=None): # Initialize this node, insert data, and set the next node if any self.data = data self.chain = node class SubSetStack: def __init__(self, data=None): # Initialize this stack, and store data if it exists def push(self, data): # Add data to the beginning of the stack def pop(self): # Remove the element at the beginning of the stack. # Return the data in the element at the beginning of the stack, or None if the stack is empty def top(self): # Return the data in the element at the beginning but does not remove it. # Return None if stack is empty. def __len__(self): # Return the number of elements in the stack def subset_sum(target, sub_list): # Returns True if Target can be formed from sub_list repeated # some arbitrary number of times. In the above function a Node…arrow_forwardFor this project, you will read an infix expression, convert it to postfix, evaluate the postfix expression, and print out the answer. You will need to define and implement your own Stack class and a Calculator class. Your Stack class should support standard stack operations, which you can implement with either a linked list or an array. You should use a class template Stack in C++, but an integer Stack class would work as well since a character would be considered a subset of integers. Your Calculator class stores an infix operation and it provides the public operations below. Feel free to add private operations and data. The Calculator class should use a character stack to convert infix to postfix (storing operators) and then uses an integer stack to evaluate the expression (storing operands). C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++ C++…arrow_forward
- Implement a method transfer in class LinkedStack. This method should transfer all elements of a stack sourceS to another stack targetS so that the element that starts at the top of sourceS is the first one to be inserted in targetS, and the element at the bottom of sourceS ends up at the top of targetS. The operation should result in sourceS being an empty stack. Test this method in the main method of LinkedStack. package stacks;public class LinkedStack<E> implements Stack<E> {/** The primary storage for elements of the stack */private SinglyLinkedList<E> list = new SinglyLinkedList<>(); // an empty list/** Constructs an initially empty stack. */public LinkedStack() { } // new stack relies on the initially empty list@Overridepublic int size() { return list.size(); }@Overridepublic boolean isEmpty() { return list.isEmpty(); }@Overridepublic void push(E element) { list.addFirst(element); }@Overridepublic E top() { return list.first(); }@Overridepublic E pop() {…arrow_forwardImplement a stack S with two queues Q1 and Q2 so that the operations PUSH (S, X) and POP(S, Y), where S is presumably a stack and X is the element to be added to S and Y is the element removed from S, are handled by the queues that function as a stack as a whole. Assume that only queues are accessible to ADT's ENQUEUE, DEQUEUE, and EMPTYQUEUE operations.Show how your function operates on a list of items (a, b, and c) that will be used as a stack by the queues Q1 and Q2.arrow_forwardIt is possible for one linear structure to be more general than another. (a) Can a Queue be implemented using a Stack? What is the level of complexity of each Queue operation? (b) Can a Stack be implemented using a Queue? What are the various Stack techniques' complexities?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education