EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 4, Problem 9E
Program Plan Intro
Queue:
- Queue is another data structure which will do insertion and deletion in FIFO(First In First Out) manner.
- Basic operations are given below:
- Enqueue: Insert an element into back of queue.
- Dequeue: Remove an item from front of queue.
Vector:
- Vector is sequence container represents array which can change its size.
- It uses dynamically allocating array for storing elements.
- Each element is allocated in each position of vector
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose you are tasked with implementing a reverse queue in which elements are enqueued at the front and dequeued at the rear The umplementation
is dynamic, and your queue class has Node pointers called front and rear, which point to the front and rear nodes in the queue respectively. The
Node struct is given below:
struct Node
char element;
Node * next ;
};
Implement the dequeue function of the reverse queue which should return the dequeued value. The function prototype is T dequeue ()
For the toolbar
(PCLor ALT+FN+F10 (Mac).
Create the generic interface GenericQueuable<T> that contains the following abstract methods:
- an abstract method insertEnd(T e) which adds the element to the Queue at end.
- an abstract method removeBegin() which removes a element from the begining of the queue.
- an abstract method printQueue() which prints the queue elements from the front of the queue to end.
- an abstract method isQueueEmpty() which returns true if the queue is empty otherwise return false.
Create GenericQueue<T> such that it implements GenericQueuable<T>. Write a GenericQueueDemo class to test the operations of GenericQueue class with two different queues.
7. Given a Queue Q, write a non-generic method that finds the maximum element in the Queue.
You may use only queue operations. No other data structure can be used other than queues. The
Queue must remain intact after finding the maximum value. Assume the class that has the
findMax method implements Comparable.
The header of the findMax method:
public Comparable findMax(Queue q)
Chapter 4 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
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
- For example: Programming generates and modifies linked lists: Typically, the software monitors two nodes: How to utilise the null reference in the node of a linked list in two common scenarios.arrow_forwardStackQueuePostfix A. Pointer_based queuea. Define the class PoiQueue with no implementation; i.e. declare the datamembers, and the function members only (Enqueue, Dequeue, IsEmpty,GetHead etc.).b. Implement the Enqueue method of the above classB. Array_based non-circular queue:a. Define the class Queue using one dimensional array representation with noimplementation; i.e. declare the data members, and the function membersonly (Enqueue, Dequeue, IsEmpty, GetHead etc.).b. Implement the Denqueue method of the above classarrow_forwardQueue example – make this generic, instead of a Queue of Customer. public class Queue { private ArrayList<Customer> line; public Queue() { line = null; } public void enqueue (Customer c) { Customer newc = new Customer (c); // copy constructor plateful.add(newc); } public Customer dequeue (Customer c) { Customer newc = line.get(0); plateful.remove(0); return newc; } } // end of class definitionarrow_forward
- 2. Given the abstract data type (ADT) for static queue template in Queue.h below template class Queue { private: T *queueArray; int queueSize; int front; int rear; int numItems; public: Queue (int); Queue (const Queue &); -Queue (); void enqueue (T); void dequeue (T &); void splitqueue (T &); bool isEmpty() const; bool isFull() const; void clear (); } ; (a) Write the full definition for the public member method splitqueue that splits the contents of a queue into two different queues i.e. Odd_queue and Even_queue. This method print the appropriate queue based on user choice of 1 and 2 where 1 is for Odd queue and 2 for Even queue.arrow_forwardC++ A queue is essentially a waiting list. It’s a sequence of elements with a front and a back. Elements can only be added to the back of the queue and they can only be removed from the front of the queue. Elements are kept in order so that the first element to enter the queue is the first one to leave it.arrow_forwardQuestion 2 (25.0 marks) The data structure shown in Figure 1 depicts an implementation of a list of two lists, that is, two linked list joined into one. In this example, the data structure is implemented to group two separate lists of numbers, one consists of lists of even numbers and the other consists of lists of odd numbers. Next Node head 6 8 2 Next List 1 7 9 Node from main list: Node from secondary list: Next Node Next Node Next List Figure 1: A list of two lists Two types of linked list are used in the above implementation. The node of the main list (highlighted in grey) consists of a content field, a next node field, and a next list field. The content node holds a value 0 for an even list and a value 1 for an odd list. The node also contains two reference fields. The first is a 'next node' that links to the first node of a secondary list, and the second is a 'next list' that links to the next link list. The node of the secondary list (non-highlighted) consists of a content…arrow_forward
- please convert this into c++ import java.util.Iterator;import java.util.NoSuchElementException; public class Queue<Item> implements Iterable<Item> { private int n; // number of elements on queue private Node first; // beginning of queue private Node last; // end of queue // helper linked list class private class Node { private Item item; private Node next; } /** * Initializes an empty queue. */ public Queue() { first = null; last = null; n = 0; } /** * Returns true if this queue is empty. * * @return {@code true} if this queue is empty; {@code false} otherwise */ public boolean isEmpty() { return first == null; } /** * Returns the number of items in this queue. * * @return the number of items in this queue */ public int size() { return n; } /** * Returns the number of items in this queue. * * @return the…arrow_forwardQuestion Assume that we have the following definition of a Linear Unordered Singly integer data. class Node { }; int data; Node "next; Node "previous; public: Node(); //getter setter for all private variables are present class List { Node *first; public: List(); //function to be implemented bool DeleteMin(); };arrow_forwardDiscuss what is meant by a generic classarrow_forward
- 1. Write code to define LinkedQueue<T> and CircularArrayQueue<T> classes which willimplement QueueADT<T> interface. Note that LinkedQueue<T> and CircularArrayQueue<T>will use linked structure and circular array structure, respectively, to define the followingmethods.(i) public void enqueue(T element); //Add an element at the rear of a queue(ii) public T dequeue(); //Remove and return the front element of the queue(iii) public T first(); //return the front element of the queue without removing it(iv) public boolean isEmpty(); //Return True if the queue is empty(v) public int size(); //Return the number of elements in the queue(vi) public String toString();//Print all the elements of the queuea. Create an object of LinkedQueue<String> class and then add some names of your friendsin the queue and perform some dequeue operations. At the end, check the queue sizeand print the entire queue.b. Create an object from CircularArrayQueue<T> class and…arrow_forwardALL TRUE OR FALSE QUESTIONS 1. A "deque" allows an application to enqueue and dequeue from both front and rear of a queue. 2. The Queue ADT of the text is defined to hold elements of type Objec 3. Java supports inheritance of interfaces. 4. The text's array-based queue implementations use the fixed-front approach. 5. If N represents the number of elements in the queue, then the dequeue method of the ArrayBoundedQueue class is O(1). 6. When an object of class LinkedQueue represents an empty queue, its rear variable is 0. 7. A standard linked list provides a good implementation of a "Deque". 8. When implementing a queue with a linked list, the front of the queue is also the front of the linked list. 9. Our LinkedQueue class implements the QueueInterface interface. 10. The text's array-based queue implementations use the floating-front approach.arrow_forwardWhich of the following terms best describes the case where a Stack class is implemented using an internal instance of List? Choose only one option.(a) Association(b) Specialization(c) Genericity(d) Composition(e) Singularityarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning