Question

In: Computer Science

Solve in C++ program. Modify the use of queue data structure such that the array used...

Solve in C++ program.

Modify the use of queue data structure such that the array used to implement the queue is dynamically allocated for a fast food autoservice

Solutions

Expert Solution

Array implementation of queue data structure

#include<bits/stdc++.h>
using namespace std; 
#define MAX_SIZE 101 
class queue_implementation
{
private:
    int array[MAX_SIZE];
    int front, rear; 
public:
     //constructor implemenatation to set intial value of front and rear 
    queue_implementation()
    {
        front = -1; 
        rear = -1;
    }
    //check if queue is empty 
    bool IsEmpty()
    {
    
        return (front == -1 && rear == -1); 
    }
    //check if queue reach its maximum size 
    bool IsFull()
    {
        return (rear+1)%MAX_SIZE == front ? true : false;
    }

    // Inserts an element in queue at rear end
    void insert_element (int x)
    {
        cout<<"Inseted element is : "<<x<<" \n";
        if(IsFull())
        {
            cout<<"Error: Queue is Overflow \n";
            return;
        }
        if (IsEmpty())
        { 
            front = rear = 0; 
        }
        else
        {
            rear = (rear+1)%MAX_SIZE;
        }
        array[rear] = x;
    }

    //dequue element at the queue implemenatation
    void remove_element ()
    {
        cout<<" Element Removed after Dequeing : "<<  "\n";
        if(IsEmpty())
        {
            cout<<"Error: Queue is Underflow\n";
            return;
        }
        else if(front == rear ) 
        {
            rear = front = -1;
        }
        else
        {
            front = (front+1)%MAX_SIZE;
        }
    }
    // Returns element at front of queue. 
    int Front()
    {
        if(front == -1)
        {
            cout<<"Error: cannot return front from empty queue\n";
            return -1; 
        }
        return array[front];
    }
   //traverse from rear to front
    void traverse()
    {
        // Finding number of elements in queue  
        int count = (rear+MAX_SIZE-front)%MAX_SIZE + 1;
        cout<<"Queue       : ";
        for(int i = 0; i <count; i++)
        {
            int index = (front+i) % MAX_SIZE; 
            cout<<array[index]<<" ";
        }
        cout<<"\n\n";
    }
};
int main()
{
   queue_implementation queue;
   cout<<"After Enqueueing : \n";
   queue.insert_element (1);   
   queue.insert_element (2);   
   queue.insert_element (3); 
   queue.insert_element (4);   
   queue.insert_element (5);
   queue.insert_element (6);   
   queue.insert_element (7);   
   queue.insert_element (8); 
   queue.insert_element (9);   
   queue.insert_element (10);
   queue.traverse();
   cout<<"After dequeing 2 elements : "<<endl;
   queue.remove_element();
   queue.remove_element();
   queue.traverse(); 
}

output_screen


Related Solutions

Create a C++ program that makes use of both concepts i.e. Array of structure and array...
Create a C++ program that makes use of both concepts i.e. Array of structure and array within the structure by using the following guidelines: 1. Create an Array of 5 Structures of Student Records 2. Each structure must contain: a. An array of Full Name of Student b. Registration Number in proper Format i.e 18-SE-24 c. An array of Marks of 3 subjects d. Display that information of all students in Ascending order using “Name” e. Search a particular student...
C++ Modify this to use a separate Boolean member to keep track of whether the queue...
C++ Modify this to use a separate Boolean member to keep track of whether the queue is empty rather than require that one array position remain empty. #include <stdio.h> #include <stdlib.h> #include <limits.h> // A structure to represent a queue struct Queue { int front, rear, size; unsigned capacity; int* array; }; // function to create a queue of given capacity. // It initializes size of queue as 0 struct Queue* createQueue(unsigned capacity) { struct Queue* queue = (struct Queue*)...
C++ Program 1–Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10...
C++ Program 1–Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill...
Write a c++program using queue to find the minimum value in a queue. Use the above...
Write a c++program using queue to find the minimum value in a queue. Use the above program for implementing queue. You must use dequeue function to read values from queue.  
You are required to modify the attached simulation program. This program currently uses an array to...
You are required to modify the attached simulation program. This program currently uses an array to implement the queue. You will modify the program so that it uses the STL queue instead. /* This is for CSC 611 class at NSU Computer Science Department This program is a modified C++ version of the C program From the Second Edition Simulation Modeling & Analysis Averill M. Law W. David Kelton */ #include using namespace std; #include #include double time = 0;...
You are required to modify the attached simulation program. This program currently uses an array to...
You are required to modify the attached simulation program. This program currently uses an array to implement the queue. You will modify the program so that it uses the STL queue instead. #include <iostream> using namespace std; #include <math.h> #include<fstream> double time = 0; int seed = 1; /* External definitions for single-server queeing system. */ const int Q_LIMIT = 100000; /* Limit on queue length. */ const int BUSY = 1; /* Mnemonics for server's being busy */ const...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
c++ program You are to use a Heap data structure for this assignment I currently work...
c++ program You are to use a Heap data structure for this assignment I currently work for an investment/insurance company and I’m looking for clients to call, ones with funds.  I need to have a schedule that shows the list of customers to call and the order to be called.  The list of customers names and phone numbers are in the file ‘NamesAndPhoneV2.txt’.  A second file contains a net worth value for each client.  The files are separated for security and protection reasons, but...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT