C program for Circular Queue

This is a C program for Circular Queue which includes insertion, Deletion, and Display of circular queue.


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define max 11
int f=-1,r=-1,que[max];
int insert(int);
int qdel();
int qdisplay();
void main()
{
int c,y;
char k;
clrscr();
do{

 printf("\n\t\t*****ENTERUR CHOICE FOR CIRCULAR QUEUE*****\n");
 printf("\n1)INSERT\n2)DELETE\n3)DISPLAY\n");
 scanf("%d",&c);
 switch(c)
  {
  case 1: printf("\nENTER THE NUMBER");
   scanf("%d",&y);
   insert(y);
   break;
  case 2: y=qdel();
   printf("\nDELETED ELEMENT IS %d",y);
   break;
  case 3: printf("\n\t\tQUUE ELEMENTS ARE:\n");
   qdisplay();
   break;
  default :
  printf("\nWRONG CHOICE");
  }
 printf("\n\nDO U WANT TO CONTINUE:(Y/N)");
 k=getch();
 }
while(k=='y'||k=='Y');
}

//Queue instertion
int insert(int x)
 {

   if((r==max-1&&f==0)||r==f-1)
  {
  printf("\nQUEUE OVERFLOW DELETE SOME ELEMENT FROM FRONT");
  return 0;
  }

   else
  {
  if(r==max-1)
   {
   r=0;
   }
  else
   {
   r++;
   }
  que[r]=x;
        }
   if(f==-1)
  {
  f++;
  }
   return 0;
   }
//QUEUE DELETION
int qdel()
 {
 int x;
 if(f==-1)
  {
  printf("\nQueue Underflow\n");
  return 0;
  }
 x=que[f];
 if(f==r)
  {
  f=-1;
  r=-1;
  return(x);
  }
 else if(f==max-1)
  {
  f=0;
  return(x);
  }
 else
  {
  f++;
  return(x);
  }
 }
 //QUEUE DISPLAY
 int qdisplay()
 {
  int i;
  if (f==-1)
  {
  printf("\nqueue is empty\n");
  return 0;
  }
  else
  {
  if(r<f)
   {
   for(i=f;i<=max-1;i++)
    printf("%d ",que[i]);
   for(i=0;i<=r;i++)
    printf("%d ",que[i]);
   }
  else
   {
   for(i=f;i<=r;i++)
    printf("%d ",que[i]);
   }
  }
  return 0;
  }


If you need any assistance on this program please let me know through comments.
Thank you.

Comments

Popular posts from this blog

Windows phone Wifi connectivity problem.

Create Excel file using Java: Apache POI - PART - 2: Line Chart