Question
Calculate the complexity of the program below : #include #include #include #include struct Queue // circular queue struct { int size; int front; int rear;
Calculate the complexity of the program below :
#include
#include
#include
#include
struct Queue // circular queue struct
{
int size;
int front;
int rear;
int *time_arr;
};
int isEmpty(struct Queue *q) // function to check is queue is empty
{
if (q->rear == q->front)
{
return 1;
}
return 0;
}
void enqueue(struct Queue *q, int time) // funntion to enqueue elements into the queue
{
q->rear = (q->rear + 1) % q->size;
q->time_arr[q->rear] = time;
}
int dequeue(struct Queue *q) // funciton to dequeue elements from queue
{
int a = -1;
q->front = (q->front + 1) % q->size;
a = q->time_arr[q->front];
}
int main()
{
// creating queue instances for gold and platinum customers
struct Queue gold;
struct Queue platinum;
// fixing size of queue as 10 , although user can change as per requirement
gold.size = 10;
platinum.size = 10;
// setting front and rear position of queue
gold.front = gold.rear = 0;
platinum.rear = 0;
platinum.front = 0;
// dynamically allocating the queue array space
gold.time_arr = (int *)malloc(gold.size * sizeof(int));
platinum.time_arr = (int *)malloc(platinum.size * sizeof(int));
printf("Enter total number of customers : ");
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Select the type of customer you are : 1.Gold 2.Platinum");
int x;
scanf("%d", &x);
int random;
if (x == 1)
{
random = rand() % 30;
enqueue(&gold, random);
printf("your expected waiting time is %d", random);
}
if (x == 2)
{
random = rand() % 30;
enqueue(&platinum, random);
printf("your expected waiting time is %d", random);
}
}
printf("");
while (isEmpty(&platinum) == 0)
{
printf("platinum customer with time %d served!!!! ", dequeue(&platinum));
}
while (isEmpty(&gold) == 0)
{
printf("gold customer with time %d served!!! ", dequeue(&gold));
}
return 0;
}
Step by Step Solution
3.51 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
The program you provided is written in C and simulates a queuing system for gold and platinum custom...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started