Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
3
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#define max 5
int queue[5];
int front;
int rear;
void enqueue(int value)
{
    if(rear==max-1)
        printf("overflow");
        else if(front==-1&&rear==-1)
        {
            front++,rear++;
            queue[rear]=value;
        }
        else
        {
            rear++;
            queue[rear]=value;
        }
        printf("\n");
}
void dequeue()
{
    if(front==-1&&rear==-1){
        printf("underflow");
    }
        else
        { 
            front++;
            if(front>rear)
            front=-1;
            rear=-1;
        }
            
    else
    {
        printf("%d\n",queue[front]);
        front++;
    }
}
void print()
{
   printf("the queue is:\n");
   for(int i=front;i<=rear;i++)
   printf("%d ",queue[i]);
}
int main()
{
    enqueue(10);
    enqueue(20);
    enqueue(30);
    enqueue(40);
    print();
    dequeue();
    dequeue();
    dequeue();
     print();




    return 0;
}