Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Write an abstract data type for a queue whose elements include both a 20-character string and an integer priority. This queue must have the following methods: enqueue, which takes a string and an integer as parameters; dequeue, which returns the string from the queue that has the highest priority; and empty. The queue is not to be maintained in priority order of its elements, so the dequeue operation must always search the whole queue.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- This chapter described the array implementation of queues that use a special array slot, called the reserved slot, to distinguish between an empty and a full queue. Write the definition of the class and the definitions of the function members of this queue design. Also, write a test program to test various operations on a queue.arrow_forwardwrite in c++ Define the 3 bolded functions for the Queue (circular array): class Queue { private: double array[10000]; int front, rear, numItems; public: Queue() {front = numItems = 0; rear = -1;} bool isEmpty(); bool isFull(); void enqueue(double d); int dequeue(); void dequeueMany(int n); //remove n values from the front void enqueueMany(double values[], int n); //add n values from the array}; Hints: void dequeueMany(int n) (hint 6 lines of code, no loops, if there are more than n elements in the queue, use math to re-compute front. Otherwise, make the queue empty. Don’t forget to update numItems. void enqueueMany(int values[], int n) (hint 3 lines of code, use a for loop, call another function, but make sure there’s enough room in the array first!! )arrow_forwardComputer science helparrow_forward
- Design an implementation of an Abstract Data Type consisting of a set with the following operations: insert(S, x) Insert x into the set S. delete(S, x) Delete x fromthe set S. member(S, x) Return true if x ∈ S, false otherwise. position(S, x) Return the number of elements of S less than x. concatenate(S, T) Set S to the union of S and T, assuming every element in S is smaller than every element of T. All operations involving n-element sets are to take time O(log n).arrow_forwardIn Java. The following is a class definition of a linked list Node:class Node{int info;Node next;}Show the instructions required to create a linked list that is referenced by head and stores in order, the int values 13, 6 and 2. Assume that Node's constructor receives no parameters.arrow_forwardclass 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 Element is: %d", queue[front]);…arrow_forward
- Help pls: Write the definitions of the following functions: getRemainingTransactionTime setCurrentCustomer getCurrentCustomerNumber getCurrentCustomerArrivalTime getCurrentCustomerWaitingTime getCurrentCustomerTransactionTime of the class serverType defined in the section Application of Queues: Simulation. serverType::serverType() { status = "free"; transactionTime = 0; } bool serverType::isFree() const { return (status == "free"); } void serverType::setBusy() { status = "busy"; } void serverType::setFree() { status = "free"; } void serverType::setTransactionTime(int t) { transactionTime = t; } void serverType::setTransactionTime() { //TODO: uncomment once getTransactionTime is defined /* int time; time = currentCustomer.getTransactionTime(); transactionTime = time; */ } void serverType::decreaseTransactionTime() { transactionTime--; }arrow_forwardParser - setup Make sure to make a Parser class (does not derive from anything). It must have a constructor that accepts your collection of Tokens. We will be treating the collection of tokens as a queue - taking off the front. It isn't necessary to use a Java Queue, but you may. We will add three helper functions to parser. These should be private: matchAndRemove - accepts a token type. Looks at the next token in the collection: If the passed in token type matches the next token's type, remove that token and return it. If the passed in token type DOES NOT match the next token's type (or there are no more tokens) return null. expectEndsOfLine - uses matchAndRemove to match and discard one or more ENDOFLINE tokens. Throw a SyntaxErrorException if no ENDOFLINE was found. peek - accepts an integer and looks ahead that many tokens and returns that token. Returns null if there aren't enough tokens to fulfill the request. Parser - parse Make sure to make a public parse method. There are no…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
- You will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forwardProblem 7: Assume that a queue class called XQueue has a no argument constructor, an enqueue() method, a dequeue() method and an isEmpty() method. Write a method that merges two given queues by copying the elements in an alternating sequence and returning the resulting combined queue. Note: make sure that you don't include unnecessary spaces in your answer! public XQueue merge(XQueue q1, XQueue q2) { XQueue neWQueue = new XQueue(); while (!q1.isEmpty() && !q2.isEmpty()) { newQueue.enqueue( #01 ); newQueue.enqueue( #02); } while (!q1.isEmpty()) { #03 ; } while (!q2.is Empty()) { #04 ; } return newQueue (); }arrow_forwardAdd the following method in the BST class that returns aniterator for traversing the elements in a BST in preorder./** Return an iterator for traversing the elements in preorder */java.util.Iterator<E> preorderIterator()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