Posted By

Linear Queue in C programming Language Insert Display Delete

Education 5

#include<stdio.h>

#define size 5

int q[size],front=-1,rear=-1;


void push(){

    int item;

    if(rear==size-1){

        printf("Queue is overflow\n");

        return;

    }

    printf("Enter your item:");

    scanf("%d",&item);

    rear=rear+1;

    q[rear]=item;

}


void pop(){

    int item;

    if(front==-1){

        printf("Jinn er nanu ese inserst kore rakhcilo naki\n");

    }

    else if(front==size+1){

        printf("Queue is empty\n");

    }

    item=q[front];

    front=front+1;

    

}


void disp(){

    int i;

    if (rear==-1)

        printf("Inserting not start yet: \n");

        else if(front==size-1){

            printf("Queue full but no data");

        }

    else

    {

        printf("Queue is ");

        if(front==-1)

            front=front+1;

        for (i = front; i <= rear; i++)

            printf("%d ", q[i]);

        printf("\n");

    }

}


int main(){

    int ch;

    while(1){

        printf("\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT\n");

        printf("Enter your choice:");

        scanf("%d",&ch);

        if(ch==1)

            push();

        else if(ch==2)

            pop();

        else if(ch==3)

            disp();

        else if(ch==4)

            break;

        else

            printf("Invalid Choice\n");

    }

    return 0;

}

Linear Queue in C programming Language Insert Display Delete

Login to comment login

Latest Jobs
  • Bangladesh Navy Welder Job Circular
    Bangladesh Navy
    Education: S.S.C/ Equivalent
    Experience: 0 Years
    Deadline: 25 Nov 2018
  • Bangladesh Navy Shipfitter Job Circular
    Bangladesh Navy
    Education: S.S.C/ Equivalent
    Experience: 0 Years
    Deadline: 25 Nov 2018
  • Bangladesh Navy Plater Job Circular
    Bangladesh Navy
    Education: S.S.C/ Equivalent
    Experience: 0 Years
    Deadline: 25 Nov 2018
  • Bangladesh Navy Diesel Fitter Job Circular
    Bangladesh Navy
    Education: H.S.C. (Vocational)
    Experience: 0 Years
    Deadline: 25 Nov 2018
  • Bangladesh Navy Carpenter Job Circular
    Bangladesh Navy
    Education: S.S.C/ Equivalent
    Experience: 0 Years
    Deadline: 25 Nov 2018