Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

#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) //function to enqueue elements into the queue
{
q->rear = (q->rear + 1)% q->size;
q->time_arr[q->rear] = time;
}
int dequeue(struct Queue *q) // function 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 jobs of type A and jobs of type B
struct Queue job_A;
struct Queue job_B;
//fixing size of queue as 10, although user can change as per requirement
job_A.size = 10;
job_B.size = 10;
//setting front and rear position of queue
job_A.front = job_A.rear = 0;
job_B.rear = 0;
job_B.front = 0;
//dynamically allocating the queue array space
job_A.time_arr =
(int *)malloc(job_A.size*sizeof(int));
job_B.time_arr =
(int *)malloc(job_B.size*sizeof(int));
printf ("Enter total number of user to apply the job : ");
int n;
scanf("%d", &n);
float TOTAL = 0;
for (int i=0; i
{
printf("Select the type of job you applied : 1.job_A 2.job_B ");
int x;
scanf("%d", &x);
int random;
if (x == 1)
{
random = rand() % 10;
enqueue(&job_A,random);
printf("Your expected waiting time is %dS. Thankyou for your patience. ", random);
TOTAL = TOTAL + random;
}
if (x == 2)
{
random = rand() % 10;
enqueue(&job_B,random);
printf("Your expected waiting time is %ds. Thankyou for your patience. ", random);
TOTAL = TOTAL + random;
}
}
float Average = TOTAL;
printf(" ");
while (isEmpty(&job_B)==0)
{
printf("job B with time expected %ds is served. ", dequeue (&job_B));
}
while (isEmpty(&job_A)==0)
{
printf("job A with time expected %dS is served. ",dequeue(&job_A));
}
printf("Average of time expected is %f", Average);
return 0;
}
image text in transcribed
<>
Task 2: Complexity Analysis - Theoretically discuss and compute the complexity of all algorithms that you implemented. The discussion will describe your understanding of the algorithm. Define the complexity of the algorithm by using Big 'O' notation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

Done

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago

Question

LO1 Understand human resource management and define human capital.

Answered: 1 week ago