C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 19SA
a.
Program Plan Intro
To calculate the index of last element of a queue.
b.
Program Plan Intro
To find the index of the first element of the queue when the next element from the queue is deleted.
c.
Program Plan Intro
To write an expression to return true when queue is non-empty, false otherwise.
d.
Program Plan Intro
To write a statement that inserts “
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose that queue is an object of type queueType<int> of size 50, the index of the first element of queue is 7, and the index of the last element of queue is 25. Also suppose that num is a variable of type int. a. How many elements are in queue?b. Write the statement that assigns the first element of queue to num.c. Write the statement that removes the first element of queue.d. Write the statement that inserts 28 into queue.
Write the expression that returns true if queue is nonempty, false otherwise.
Determine if the following are true or false
A "glass" queue allows an application to peek at the front or rear values of a queue.
The enqueue and dequeue queue operations are inverses of each other. Therefore, performing an enqueue followed by a dequeue is always equivalent to performing a dequeue followed by an enqueue.
A "glass" queue allows an application to peek at any value in a queue.
A java interface can inherit from at most one other interface.
Chapter 18 Solutions
C++ Programming: From Problem Analysis to Program Design
Knowledge Booster
Similar questions
- Write a program for implementing queue using linked lists, for which you should use a structure to create a node with data and the next pointer. The program should be able to insert, delete and display nodes in the queue. The user will be asked to enter his choice either to insert a node (enqueue), delete a node (dequeue), display or to exit from the program.The options for the user should be as the following:1. Insert a node (Enqueue)2. Delete a node (Dequeue)3. Display4. Exit For example if user selected option 1 then the following should appear in the output:Enter the value to insert:Node is inserted If user selected option 2 then the following should appear in the output:Deleted Element is: If the user selected option 3 then the program should display the elements that are available in the queue The program will keep on running and taking inputs from the user until he selects the 4th option to exit.arrow_forwardIn Java In this assignment, you should provide a complete CircularQueueDriver class that fullytests the functionality of your CircularQueue class that you have improved in Lab 8. YourCircularQueueDriver class should:• Instantiate a 3-element CircularQueue.• Use a loop to add strings to the queue until the add method returns false (whichindicates a full queue).• Call showQueue.• Use a loop to remove strings from the queue until the remove method returns null(which indicates an empty queue). As you remove each string from the queue, print theremoved string.Sample Run:Monsieur AMonsieur BMonsieur Cremoved: Monsieur Aremoved: Monsieur Bremoved: Monsieur C CircularQueue Class: public class CircularQueue { private String[] queue; // array that implements a circular queue private int length = 0; // number of filled elements private int capacity; // size of array private int front = 0; // index of first item in queue private int rear = 0; // one past the index of the last item…arrow_forwardFind the error in each of the following code segments // A linked implementation of a queue int dequeue() { if(empty()) throw new EmptyQueueException(); int value = front.value; front ++; return value; }arrow_forward
- Given the value of queue(Q), execute the given code and answer the questions. Assume that Q iscircular with the size limit of 6. Thanks!!!arrow_forwardFor the Queue use the java interface Queue with the ArrayDeque classFor the Stack use the java Deque interface with the ArrayDeque classFor the LinkedList, use the java LinkedList class Also, when you are asked to create and use a Queue, you can use only those methods pertaining to the general operations of a queue (Enqueue: addLast, Dequeue: removeFirst, and peek() Similarly, when you are asked to create and/or use a stack, you can use only those methods pertaining to the general operations of a Stack (push: addFirst, pop:removeFirst, and peek() ) Your code should not only do the job, but also it should be done as efficiently as possible: fast and uses no additional memory if at all possible Questions Write a method “int GetSecondMax(int[] array)” . this method takes an array of integers and returns the second max value Example: if the array contains: 7, 2, 9, 5, 4, 15, 6, 1}. It should return the value: 9arrow_forwardCreate Pseudocode for this class Queue { private static int front, rear, capacity; private static int queue[]; Queue(int c) { front = rear = 0; capacity = c; queue = new int[capacity]; } static void queueEnqueue(int data) { if (capacity == rear) { System.out.printf("\nQueue is full\n"); return; } else { queue[rear] = data; rear++; } return; } static void queueDequeue() { if (front == rear) { System.out.printf("\nQueue is empty\n"); return; } else { for (int i = 0; i < rear - 1; i++) { queue[i] = queue[i + 1]; } if (rear < capacity) queue[rear] = 0; rear--; } return; } static void queueDisplay() { int i; if (front == rear) { System.out.printf("\nQueue is Empty\n"); return; } for (i = front; i < rear; i++) { System.out.printf(" %d <-- ", queue[i]); } return; } static void queueFront() { if (front == rear) { System.out.printf("\nQueue is Empty\n"); return; } System.out.printf("\nFront…arrow_forward
- Write a method to find the largest number in a given queue. The Objects in the queue are integers. You are using the standard Queue class that we discussed in this course. The Queue class has all the standard queue methods, such as, enqueue, dequeue, size, and dequeueAll. The Queue object, q, in the parameter of the method must contain the same elements in the same sequence before leaving the method as they were when entering the method. You are not allowed to use any temporary container (such as another queue, or a stack, or an array, or a linked list.) You can create variables of primitive data types (such as, an integer.) You must use the following header. public int largestNum(Queue q){arrow_forwardWhat does the following function do?void mystery(queueType<int>& q){stackType<int> s;while (!q.isEmptyQueue()){s.push(q.front());q.deleteQueue();}while (!s.isEmptyStack()){q.addQueue(2 * s.top());s.pop();}}arrow_forwardIf the elements “A”, “B”, “C” and “D” are placed in a queue and are removed one at a time, in what order will they be removed?arrow_forward
- What values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(6), enqueue(4), dequeue(), enqueue(3), enqueue(9), dequeue(), dequeue(), enqueue(1), enqueue(2), dequeue(), enqueue(8), enqueue(7), dequeue(), dequeue(), enqueue(5), dequeue(), dequeue(). Group of answer choices a) 6, 4, 3, 9, 1, 2, 8, 7 b) 6, 4, 3, 9, 1, 2, 8, 7, 5arrow_forwardWhat values are returned during the following sequence of queue operations, if executed on an initially empty queue? enqueue(6), enqueue(4), dequeue(), enqueue(3), enqueue(9), dequeue(), dequeue(), enqueue(1), enqueue(2), dequeue(), enqueue(8), enqueue(7), dequeue(), dequeue(), enqueue(5), dequeue(), dequeue(). Group of answer choices a) 6, 4, 3, 9, 1, 2, 8, 7 b) 6, 4, 3, 9, 1, 2, 8, 7, 5 2. What values are returned during the following series of stack operations, if executed upon an initially empty stack? push(4), push(2), pop(), push(1), push(7), pop(), pop(), push(8), push(9), pop(), push(6), push(5), pop(), pop(), push(3), pop(), pop(). Group of answer choices a) 4, 2, 7, 9, 5, 3 b) 4, 2, 1, 7, 8, 9, 6, 5, 3 c) 2, 7, 1, 9, 5, 6, 3, 8arrow_forwardWhat do we call the first element in a queue? (The next to be serviced)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education