SAVITIBAI PHULE UNIVERSITY OF PUNE
S. Y. B.Sc. (Computer Science) Semester III
Practical Examination
SUBJECT: CS-233 Practical course based on CS231
/* Q. 2 A doubly ended queue allows additions and deletions from both the ends that
is front and rear. Initially additions from the front will not be possible. To avoid
this situation, the array can be treated as if it were circular. Implement a
queue library (dstqueue.h) of integers using a static implementation of the
circular queue and implementing the following operations.
a. isFull(Q)
b. addFront(Q)
c. getRear(Q)
d. deleteRear(Q)
*/
// File name : "dstqueue.c"
#include"dstqueue.h"
int init(struct Queue *q)
{
q->front = q->rear = -1;
}
int isEmpty(struct Queue *q)
{
if(q->front == q->rear)
{
return 1;
}
else{
return 0;
}
}
int isFull(struct Queue *q)
{
if(q->rear == MAX-1)
{
return 1;
}
else{
return 0;
}
}
int addFront(struct Queue *q, int x)
{
if(isFull(q) == 1)
{
printf("The queue is overflow...");
return 1;
}
else{
q->data[++(q->front)] = x;
}
return 0;
}
int getRear(struct Queue *q)
{
if(isEmpty(q) == 1)
{
printf("The stack is underflow...");
return 1;
}
else{
return q->data[q->rear];
}
}
int deleteRear(struct Queue *q)
{
if(isEmpty(q) == 1)
{
printf("The stack is underflow...");
return 1;
}
else{
return q->data[++(q->rear)];
}
}
No comments:
Post a Comment