Q:Question:program A. Crea Creates a Circular queue using tenPerson[] array structure(copy from array into queue will be
Question:
Creates a Circular queue using tenPerson[] array structure(copy from array into queue will be done).
B. Delete all the elements of queue and list all the deleted items and deleted location from the monitor.
#include
#include
#include
#define MAXELEMENTS 20
#define TRUE 1
#define FALSE 0
// circular Queue insertion and deletion functions
struct person
{
int empNo;
char name[12];
int age;
char sex;
};
struct queue
{
struct person allPerson[15];
int front , rear;
};
// prototype
void cqinsert(struct queue * , struct person temp);
struct person cqdelete(struct queue *);
int empty(struct queue *);
int main(void)
{
int cnt=0;
struct person tenPerson[10]={123,"Ahmet", 21, 'M',
234,"Sevgi", 26, 'F',
128,"Osman",18,'M',
432,"Mert",27,'M',
287,"Ayse",34,'F',
423,"Kemal", 21, 'M',
634,"Lale", 16, 'F',
828,"Sefer",15,'M',
252,"Meral",27,'F',
887,"Demet",34,'F'};
struct person temp;
struct queue q;
q.front = q.rear = MAXELEMENTS - 1;
// First part Insertion into Circular Queue
printf("INSERTION INTO Queue Using Array");
do
{
temp=tenPerson[cnt++];
cqinsert(&q ,temp);
}
while (cnt<10);
// Deletion from queue
printf("DELETION FROM QUEUS");
do
{
temp = cqdelete(&q);
printf("Deleted Person Info =%d %s %d %c",temp.empNo,temp.name,temp.age,temp.sex);
}
while (!empty(&q));
return 0;
}
void cqinsert(struct queue *pq , struct person temp)
{
/* make room for new element */
if (pq->rear == MAXELEMENTS - 1)
pq->rear = 0;
else
(pq->rear)++;
if (pq->rear == pq->front) {
printf("Queue overflow");
getchar(); getchar();
exit(1);
}
pq->allPerson[pq->rear] = temp;
printf("Perno=%d Name = %s Age = %d ",
pq->allPerson[pq->rear].empNo, pq->allPerson[pq->rear].name, pq->allPerson[pq->rear].age);
}
int empty(struct queue *pq)
{
return((pq->front == pq->rear) ? TRUE : FALSE);
}
struct person cqdelete(struct queue *pq)
{
if (empty(pq)) {
printf("Queue underflow ");
exit(1);
}
if (pq->front == MAXELEMENTS - 1)
pq->front = 0;
else
(pq->front)++;
return(pq->allPerson[pq->front]);
}
2)Using circular queue which is populated at step A, Write a program that will
1. Create two new circular queues, one for Male and one for Female employees. These new queues will be created during the deletion of circular queue and use sex fields for determining Male(M) and Female(F) queues.
2. List the content of Male queue and Female queue during delete operation of each queues.
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang