/**WRITE A PROGRAM TO IMPLEMENT QUEUE USING ARRAYS THAT PERFOMS FOLLOWING OPERATIONS: ENQUEUE , DEQUEUE , DISPLAY**/

(SIMPLE QUEUE PROGRAM IN C | DS practical gtu)

WRITE A PROGRAM TO IMPLEMENT QUEUE USING ARRAYS THAT PERFOMS FOLLOWING OPERATIONS: ENQUEUE , DEQUEUE , DISPLAY



  • HERE IS A CODE OF SIMPLE QUEUE USING IF ELSE IN C PROGRAM:- (SIMPLE QUEUE PROGRAM IN C | DS practical gtu)
Continue reads below

INPUT:


 
//code written by www.techsayright.blogspot.com//

#include<stdio.h>

#include<conio.h>

#define max 5

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

void display()

{

 if(front==-1 || front>rear)

 {

  printf("\n queue is underflow");

 }

 else

 {

  printf("\n the element of queue:");

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

  {

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

  }

  printf("\n");

 }

}

void enqu()

{

 int x;

 printf("\nenter the value:");

 scanf("%d",&x);

 if(rear>=max-1)

 {

  printf("\nqueue is overflow");


 }

 else

 {

  if(rear==-1 || front==-1)

  {

   printf("inserted element is %d\n",x);

   front=rear=0;

   q[rear]=x;

  }

  else

  {

   printf("inserted element is %d\n",x);

   rear++;

   q[rear]=x;

  }

 }

 display();

}

void dequ()

{

 if(front==-1 || front>rear)

 {

  printf("\nqueue is underflow");

  return ;

 }

 else

 {

  printf("deleted element from queue is:%d\n",q[front]);

  front=front+1;

 }

 display();

}

void main()

{

 int choice;

 clrscr();


 do

 {

  printf("\n select from \n1-enqueue \n2-dequeue \n3-display \n4-exit \nenter the choice:");

  scanf("%d",&choice);


  switch(choice)

  {

   case 1:

    enqu();

    break;

   case 2:

    dequ();

    break;

   case 3:

    display();

    break;

   case 4:

    break;

   default:

    printf("\nenter the  valid choice");

  }

 }while(choice!=4);

getch();

}


OUTPUT:



*HAPPY CODING*☺

Post a Comment

Hii

أحدث أقدم