Subscribe Us

Responsive Advertisement

Advertisement

problem 27 cd(queue and circular queue using array)

 


problem 27 cd(queue and circular queue using array)



problem 27 cd(queue and circular queue using array)

#include<stdio.h>

#define size 10

int total=0;

int rear=-1;

int front=0;

int queue[size];

void enqueue(int val)

{

    if(total>=size)

    {

        printf("Overflow\n");

        return ;

    }

    rear=(rear+1)%size;

    queue[rear]=val;

    total++;

}

int dqueue()

{

    if(total<=0)

    {

        printf("underflow\n");

        return -1;

    }

    int val;

    val=queue[front];

    queue[front]=-1;

    front=(front+1)%size;

    total--;

    return val;

}

int main()

{

    enqueue(10);

    enqueue(20);

    printf("%d ",dqueue());

    printf("%d ",dqueue());

    printf("%d ",dqueue());

}


Post a Comment

0 Comments