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 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
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)
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).
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.
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
- StackQueuePostfix 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_forwardGiven the following definition for a LinkedList: // LinkedList.h class LinkedList { public: LinkedList(); // TODO: Implement me void printEveryOther() const; private: struct Node { int data; Node* next; }; Node * head; }; // LinkedList.cpp #include "LinkedList.h" LinkedList::LinkedList() { head = nullptr; } Implement the function printEveryOther, which prints every other data value (i.e. those at the odd indices assuming 0-based indexing).arrow_forwardCreate 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.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_forwardConsider the following implementation of the node and doubly linked-list: template <class type>class node{public:type info;node<type> * next;// nextnode<type> * prev;//back }; template <class type>class doubly_linked_list{//data membersprivate:node<type> *head, *tail;int length;public:doubly_linked_list(){head = tail = NULL;length = 0;}bool isEmpty(){ // return (head==NULL);if (head == NULL)return true;elsereturn false;} void Append(type e){node<type> *newnode = new node<type>;newnode->info = e;if (isEmpty()){newnode->next = NULL;newnode->prev = NULL;head = newnode;tail = newnode;}else{tail->next = newnode;newnode->prev = tail;newnode->next = NULL;tail = newnode;}++length; } void Display(){if (isEmpty()) { cout << "The linked list is empty !!!!"; return; }cout << "list elements: ";node<type> * current = head;while (current != NULL){cout << current->info << " ";current =…arrow_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
- Create 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_forwardThe following is a class definition of a linked list Node:class Node{int info;Node next;}Assume that Node's constructor receives no parameters. For each line of the code below, explain what memory is being allocated by JVM (Java Virtual Machine). int counter = 0; double dd; String str = "New Label"; Node myNode; myNode = new Node(); Subject: Java Programmingarrow_forwardConsider the following implementation of the node and doubly linked-list: template <class type>class node{public:type info;node<type> * next;// nextnode<type> * prev;//back }; template <class type>class doubly_linked_list{//data membersprivate:node<type> *head, *tail;int length;public:doubly_linked_list(){head = tail = NULL;length = 0;}bool isEmpty(){ // return (head==NULL);if (head == NULL)return true;elsereturn false;} void Append(type e){node<type> *newnode = new node<type>;newnode->info = e;if (isEmpty()){newnode->next = NULL;newnode->prev = NULL;head = newnode;tail = newnode;}else{tail->next = newnode; newnode->prev = tail;newnode->next = NULL;tail = newnode;}++length; } void Display(){if (isEmpty()) { cout << "The linked list is empty !!!!"; return; }cout << "list elements: ";node<type> * current = head;while (current != NULL){cout << current->info << " ";current =…arrow_forward
- Implement Circular Queue ADT using a circular doubly linked list, the ADT have to be in following convention: Template Class CircularQueue { DoubleList dll; ///////////////////////// Setter/Getters Constructors/ destructor Virtual bool Enqueue(type value)=0; Virtual bool Dequeue(type &value)=0; Virtual bool Front (type &value)=0; Virtual bool Rear (type &value)=0; Virtual void Display( )=0; //Any other function } Task is to extend this class by MyCircularQueue and override the above all pure virtual functions. program in c++.arrow_forwardImplement Circular Queue ADT using a circular doubly linked list, the ADT have to be in following convention: Template Class CircularQueue { DoubleList dll; ///////////////////////// Setter/Getters Constructors/ destructor Virtual bool Enqueue(type value)=0; Virtual bool Dequeue(type &value)=0; Virtual bool Front (type &value)=0; Virtual bool Rear (type &value)=0; Virtual void Display( )=0; //Any other function } Task is to extend this class by MyCircularQueue and override the above all pure virtual functions. In C++arrow_forward2. 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_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