Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #define FALSE 0 #define TRUE 1 /*A Node declaration to store a value and a link*/ struct Node { int val; struct Node

#include #include

#define FALSE 0 #define TRUE 1

/*A Node declaration to store a value and a link*/ struct Node { int val; struct Node *next; };

struct QueueRecord { struct Node *front; /* pointer to front of queue */ struct Node *rear; /* pointer to rear of queue */ int size; /* number of items in queue */ }; typedef struct QueueRecord *Queue;

Queue CreateQueue(int); void MakeEmptyQueue(Queue); int QueueSize(Queue); void Enqueue(int, Queue); int Dequeue(Queue); int FrontOfQueue(Queue); int RearOfQueue(Queue); int IsEmptyQueue(Queue); void DisplayQueue(Queue);

int main() {

}

/*This function initialises the queue*/ Queue CreateQueue(int maxElements) { Queue q; q=(struct QueueRecord*)malloc(sizeof(struct QueueRecord)); if(q==NULL){ printf("Out of memory"); return 0;} MakeEmptyQueue(q); return q; }

/*This function sets the queue size to 0, and creates a dummy element and sets the front and rear point to this dummy element*/ void MakeEmptyQueue(Queue q) { struct Node *dummy; dummy= (struct Node *) malloc(sizeof(struct Node)); q->front=dummy; q->size=0; q->front->next=NULL; q->rear=q->front; }

/*Shows if the queue is empty*/ int IsEmptyQueue(Queue q) { if(!q->size==0) return 1; else return 0; }

/*Returns the queue size*/ int QueueSize(Queue q) { return q->size; }

/*Enqueue - Adds a new element to the queue, simly creates a node and adds it to the rear of the queue*/ void Enqueue(int x, Queue q) { struct Node *newnode; newnode= (struct Node *) malloc(sizeof(struct Node)); newnode->next=NULL; newnode->val=x; q->rear->next=newnode; q->rear=newnode; q->size+1; }

/*Dequeue - Removes a node from the queue, basically removes a node from the front of the queue*/ int Dequeue(Queue q) { int val; struct Node *delnode; delnode=(struct Node *) malloc(sizeof(struct Node)); delnode=q->front->next; q->front->next=q->front->next->next; val=delnode->val; free(delnode); q->size-1; return val; }

/*Returns the value stored in the front of the queue*/ int FrontOfQueue(Queue q) { if (!IsEmptyQueue(q)) return q->front->next->val; else { printf("The queue is empty "); return -1; } }

/*Returns the value stored in the rear of the queue*/ int RearOfQueue(Queue q) { if (!IsEmptyQueue(q)) return q->rear->val; else { printf("The queue is empty "); return -1; } }

/*Displays the content of the queue*/ void DisplayQueue(Queue q) { struct Node *print;

print = q->front->next;

while (print != NULL) { printf("--> %d ", print->val); print = print->next; } printf(" "); }

I need simple as possible not to complicated

-Write a function called orderElement() that continuously asks user to enter an integer value and stores them in the queue, and once the user enters -1 this displays the list of the entered integer numbers in the order they are entered.

-Using only the queue functions (e.g., enqueue, dequeue, etc.), write a function called copyQueue() that copies the content of one queue to another.

-Modify the function you created in the previous step such that copyQueue() function copies the content of one queue to another and the original queue content will still be the same after the copying operation.

-Write a function called deleteNegatives() that only uses queue functions and deletes the negative values in a queue. The queue content will be the same but the content will not have negative values.

-Modify your queue such that it stores the name, salary and id of an employee. You will then need to update all the relevant functions to enqueue and dequeuer an employee. Write a function called employeeOrder() that asks the user to continuously enter an employee until they enter an employee with id -1. When they do that, this function will display the details of the employees in the entered order.

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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

What is an efficient transfer?

Answered: 1 week ago