Tuesday, October 15, 2024

SYBSc (CS) Sem III : Data Structure Slip 14 Que - 2

 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)];

    }

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File name : "dstqueue.h"

#include<stdio.h>
#include<stdlib.h>

struct Queue
{
       int data;
       struct Queue *Next;
};

int init(struct Queue *Q);
int isEmpty(struct Queue *Q);
int isFull(struct Queue *q);
void addFront(struct Queue *Q, int x);
int getRear(struct Queue *Q);
int deleteRear(struct Queue *Q);



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File name : "main.c"

#include"dstqueue.h"

int main()
{
    struct Queue q;
    
    int ch, num;
    
    init(&q);
    
    do{
       printf("\n1. Insert \n2. Delete \n3. Display \n4. Exit \n");
       scanf("%d", &ch);
       
       switch(ch)
       {
            case 1: 
                 printf("Enter the element to insert into queue: ");
                 scanf("%d", &num);
                 
                 addFront(&q, num);                 
                 break;
                 
            case 2:
                 printf("The current element : %d", getRear(&q));
                 break;
            
            case 3:
                 printf("The deleted element : %d", deleteRear(&q));
                 break;
            default:
                 printf("Thank you visit again ....\n\n");
                 break;          
       }
    
    }while(ch != 4);
    
    system("pause");
    return 0;
}

No comments:

Post a Comment

SYBSc (CS) Sem III : Data Structure Slip 14 Que - 2

  SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical cours...