SAVITIBAI PHULE UNIVERSITY OF PUNE
S. Y. B.Sc. (Computer Science) Semester III
Practical Examination
SUBJECT: CS-233 Practical course based on CS231
/* Q. 1. Implement a linear queue library (st_queue.h) of integers using a static implementation of the queue and implementing the init(Q), add(Q) and peek(Q) operations. Write a program that includes queue library and calls different queue operations.*/
/// File name : "st_queue.c"
#include"st_queue.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 add(struct Queue *q, int x)
{
if(isFull(q) == 1)
{
printf("The queue is overflow...");
return 1;
}
else{
q->data[++(q->rear)] = x;
}
return 0;
}
int peek(struct Queue *q)
{
if(isEmpty(q) == 1)
{
printf("The stack is underflow...");
return 1;
}
else{
return q->data[++(q->front)];
}
}
void Display(struct Queue *q)
{
int i = 0;
printf("\n The Queue elements are : \t");
for(i = q->front + 1; i <= q->rear; i++)
printf("%d\t", q->data[i]);
}
No comments:
Post a Comment