
Problem 1
Consider an array-based queue implementation. Suppose we wish to use an extra bit
in queue records to indicate whether a queue is empty.
1. Modify the declarations and operations for a circular queue to accommodate this feature.
2. Would you expect the change to be worthwhile?
Problem 2
Given the following specification of a front operation for queue:
ItemType Front
Function: Returns a copy of the front item on the queue.
Precondition: Queue is not empty.
Postcondition: Queue is not changed.
1. Write this operation as client code, using operations from the QueType class. (Remember,
the client code has no access to the private variables of the class).
2. Write this function as a new member function of the QueType class.
Problem 3
Implement the following specification for a Boolean function in the client program
that returns true if two queues are identical and false otherwise.
Boolean Identical(QueType queue1, QueType queue2)
Function: Determines if two queues are identical.
Precondition: queue1 and queue2 have been initialized.
Postconditions: Queues are unchanged.
You may use any of the member functions of QueType. But, you may not assume any
knowledge of the queue’s implementation.
Problem 4
Write the body for a function that replaces each copy of an item in a queue with
another item. Use the following specification. (This function is in the client program.)
ReplaceItem(QueType queue, int oldItem, int newItem)
Function: Replaces all occurrences of oldItem with newItem.
Precondition: Queue has been initialized.
Postcondition: Each occurrence of oldItem in queue replaced by newItem.
You may use any of the member functions of QueType. But, you may not assume any
knowledge of the queue’s implementation.

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- 1. consider an array based queue implementation. suppose we wish to use an extra bit in the queue records to indicate whether a queue is empty. a. Modify the declarationsand operations for a circular queue to accomodate this feature. b. Would you see the change to be worthwide.arrow_forwardThe program inserts a number of values into a priority queue and then removes them. The priority queue treats a larger unsigned integer as a higher priority than a smaller value. The priority queue object keeps a count of the basic operations performed during its lifetime to date, and that count is available via an accessor. In one or two places I have put statements such as op_count++;, but these are incomplete. We only count operations involved in inserting and removing elements, not auxiliary operations such as is_empty() or size() The class implements a priority queue with an unsorted vector. Your assignment is to re-implement the priority queue implementation using a heap built on a vector, exactly as we discussed in class. Leave the framework and public method interfaces completely unchanged. My original test program must work with your new class. You will have to write new private methods bubble_up and percolate_down. You should not implement heapify or heapsort. #include…arrow_forwardGiven the following specification of a front operation for queue:ItemType Front Function: Returns a copy of the front item on the queue. Precondition: Queue is not empty. Postcondition: Queue is not changed. 1. Write this operation as client code, using operations from the QueType class. (Remember,the client code has no access to the private variables of the class). 2. Write this function as a new member function of the QueType class. help me with complete codearrow_forward
- a) Given a typical Queue q with elements [E,D,C,B,A] (where Front/left of Queue at E and Rear/right of Queue at A), determine and list elements of the updated Queue in the similar form (Front/left and Rear/right), after the following execution: q.enqueue( q. dequeue() ) q. enqueue( G ) q.dequeue() b) Given a typical Stack s with elements [T,W,X,Y,Z] (where Top/left of Stack at T) and a typical Queue q with elements [E,D,C,B,A] (where Front/left of Queue at E and Rear/right of Queue at A), determine and list elements of the updated Stack and those of the updated Queue in their similar forms after the following execution: q. enqueue( s.pop() ) s.push( R ) q.enqueue( s. peek () ) s. push( q.dequeue() ) q.enqueue( s. pop() ) OParrow_forwardJava Algorithm Programming Question Implement the ADT queue by using a circular linked list. Recall that this list has only an external reference to its last note. Example Output: Create a queue: isEmpty () returns true Add to queue to get Joe Jess Jim Jill Jane Jerry isEmpty () returns false Testing getFront and dequeue: Joe is at the front of the queue. Joe is removed from the front of the queue. Jess is at the front of the queue. Jess is removed from the front of the queue. Jim is at the front of the queue. Jim is removed from the front of the queue. Jill is at the front of the queue. Jill is removed from the front of the queue. Jane is at the front of the queue. Jane is removed from the front of the queue. Jerry is at the front of the queue. Jerry is removed from the front of the queue. The queue should be empty: isEmpty() returns true Add to queue to get Joe Jess Jim Testing clear: isEmpty() returns true Add to queue to get Joe Jess Jim Joe is at the front of the queue. Joe is…arrow_forwardJava: Which of the following operations has the least running time in a Queue (assume that only Queue interface operations are available; some operations may require use of an additional temporary queue)? Multiple choice. Deleting the element at the rear of the queue Checking if an element x is present in the queue Finding the number of elements in the queue all of the above have identical worst case running timearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





