Computer Science: An Overview (12th Edition)
12th Edition
ISBN: 9780133760064
Author: Glenn Brookshear, Dennis Brylow
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8.1, Problem 4QE
Program Plan Intro
Queue:
It is a list in which the entries are removed only at the head and new entries are inserted only at the tail. It is a first in first out process.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In a bank, customers wait in a queue (q0) for their turn to complete a transaction. Customers who come first are
served first. At a certain point when there are lots of customers waiting, a decision is taken to split the queue
elements into two empty queues q1 and q2. The customers are split based on the alphabetical order of their first
names. Customers with first name starting A-H are added to q1 while the others (first name starting I-Z) are
added to q2.
In an application, write a method named splitQueue (in an application) that accepts as parameters 3 queues, the
original queue (q0) and two empty queues (q1 and q2) to be filled as described above. Write also a main
method in which you read the first names of customers from the user, fill them into q0 and call the method
splitQueue to split q0 elements into q1 and q2. After the split display the elements of q1 first then those of q2.
The header of the method is:
public static void splitQueue ( Queue q0, Queue q1, Queue q2)
Note:…
Implement solution for remove(int id)
removes the Student associated with this id; if the id is not found in the table or on the waitlist, then it should return null; otherwise, it should return the Student associated with the id. If the student that is removed was registered, then this student should be replaced by the student who is first in the waitlist queue. If the student who is removed was on the waitlist, then they should just be removed from the waitlist. You should go directly to slot id % m rather than iterating through all the slots.
public class Course {
public String code;
public int capacity;
public SLinkedList<Student>[] studentTable;
public int size;
public SLinkedList<Student> waitlist;
public Course(String code) {
this.code = code;
this.studentTable = new SLinkedList[10];
this.size = 0;
this.waitlist = new SLinkedList<Student>();
this.capacity = 10;
}
public…
USING C LANGUAGE
Use a queue to generate binary number strings.
Hint: For example, enqueue "1" onto the queue.
Then dequeue "1", print it, and place "10" and "11" on the queue (add "0" and "1" at the end of the printed item "1"). Dequeue "10", print it, and add "100" and "101" onto the queue, etc. Strings only may be used and you are allowed to use string.h. You can input n from the user and count from 1 to n in binary using the queue.
Suppose you have an empty string and you want to print 1 to 9 binary numbers. Your code will generate the following output:
1 print
10 11 enque 0 and 1
10 print
100 101 enque 0 and 1
….
You can either choose an array implementation or a linked list implementation of the queue.
Chapter 8 Solutions
Computer Science: An Overview (12th Edition)
Ch. 8.1 - Give examples (outside of computer science) of...Ch. 8.1 - Prob. 2QECh. 8.1 - Prob. 3QECh. 8.1 - Prob. 4QECh. 8.1 - Prob. 5QECh. 8.2 - In what sense are data structures such as arrays,...Ch. 8.2 - Prob. 2QECh. 8.2 - Prob. 3QECh. 8.3 - Prob. 1QECh. 8.3 - Prob. 2QE
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
Similar questions
- Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants? Stack Queue ArrayList Linked Listarrow_forwardA company "XYZ" is manufacturing two types of grinders, called X and Y. The grinders X and Y are kept in a row. Write an algorithm using the queue data structure to replace all grinders X in the row with grinder Y. Illustrate your algorithm for any sample input.arrow_forwardUsing only the algorithm in queue ADT . Write an Algorithm called catqueue that concatenates two queues together. The second Queue is to be put at the end of first Queue.arrow_forward
- Write a program for the implementation of a queue using singly linked list. The elements of the queue should be strings of length at most 20 characters. Print the queue and do the following operations on the created queue : (a) Insert a new element. (b) Delete an element from the queue.arrow_forwardUsing Queues Operation Enqueue. Dequeue. Write a algorithm of method names Contain Equal that takes the strrings "aaabbb" in queue form as input and returns that the strings contain equal numbers of a's and b's A A A B B B Quput Must be Like: Both A's and B's are Equal In Quantity Which Is 3.arrow_forwardPlease help me with this! The countOff() method displays the name of each officer removed from the queue, in the order in which they are removed, and displays the name of the officer that goes for help. For example, the output for the queue of defenders above with a count of 4 would appear as:Defenders leaving the queue are: Horace Alsbury, PVT, Kentucky, survivorSimon Arreola, —, —, survivorPeter James Bailey III, PVT, Kentucky, fatalityJohn J. Ballentine, PVT, Pennsylvania, fatalityRobert Allen, PVT, Virginia, fatalityMicajah Autry, PVT, North Carolina, fatalityWilliam Charles M. Baker, CPT, Missouri, fatalityJames L. Allen, PVT, Kentucky, survivorJesse B. Badgett, —, Texas, survivorRichard W. Ballentine, PVT, Scotland, fatalityJosé María Arocha, —, —, survivorJuan Abamillo, SGT, Texas, fatalityIsaac G. Baker, PVT, Arkansas, fatalityJuan A. Badillo, SGT, Texas, fatalityJohn Ballard, —, —, fatalityMiles DeForest Andross, PVT, Vermont, fatality The defender going for help is: George…arrow_forward
- A circular queue of size 5 has 3 elements 10, 20 and 40 where F=2 and R=4. After inserting 50 and 60, what is the value of F and R. Now, insert 30 in the queue, and explain what will happen? Delete 3 elements from the queue and insert 70, 80 and 90. Show the sequence of steps with necessary diagrams with the value of F and R.arrow_forwardAssume that you have the Queue implementation. Write a method in Queue class so that this method adds the multiplication of the number given in the parameter with the last stored number in queue. (If you do not use Queue, you will not get any credits,). Your answer: Font Size BIU 2三三 = X x E E E の !!arrow_forwardWrite a program in Python to show how a queue works using empty, size, front, back, push item onto queue, and push item off queue.arrow_forward
- Using Queues Operation Enqueue,Dequeue, Write a algorithm of method names Contain_Equal that takes the strrings “aaabbb” in queue form as input and returns that the strings contain equal numbers of a’s and b’s A A A B B B Ouput Must be Like: Both A’s and B’s are Equal In Quantity Which Is 3.arrow_forwardImagine a ballroom with two kinds of dancers: leaders and followers. Dancers of both kinds wait in two separate queues before entering the dance floor. When a leader arrives, it checks to see if there is a follower waiting. If so, they can both proceed. Otherwise it waits. Similarly, when a follower arrives, it checks for a leader and either proceeds or waits, accordingly. Make sure that the next pair of leader/follower may dance only after the previous pair is done.Write the pseudocode for leaders and followers that enforces these constraints.arrow_forwardUsing Queues Operation Enqueue Degueue. Write a algorithm of method names Contain Equal that takes the strrings "aaabbb" in queue form as input and returns that the strings contain equal numbers of a's and b's A A A B B В Qurut Must be Like: Both A's and B's are Equal In Quantity Which Is 3.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