Tuesday, July 2, 2013

C PROGRAM FOR LINEAR QUEUE

/*PROGRAM TO TEST INSERTION & DELETION OPERATION IN LINEAR QUEUE*/
#include<stdio.h>
#include<conio.h>
void main() {
int max=5, n, r=0, f=0, a[5], v, item, i;
clrscr();
do {
printf("\nChoice are:");
printf("\n1: INSERTION");
printf("\n2: DELETION");
printf("\n3: DISPLAY ITEMS");
printf("\n4: EXIT");
printf("\nEnter your choice:");
scanf("%d", &n);
switch(n) {
case 1: {
 if(r==max)
 printf("\nQUEUE REACHED LIMIT\n");
 else {
 printf("\nEnter insertion value:");
 scanf("%d", &v);
 a[r]=v;
 r++; }
 break;
}
case 2: { if(f==r)
 printf("\nQUEUE IS EMPTY");
 else {
 item=a[f];
 f++;
 printf("\nDeleted item is: %d", item); }
 break;
}
case 3: { printf("\nThe items in the QUEUE are:");
 for(i=f;i<r;i++)
 printf(" %d ", a[i]);
 break; }
}
}
while(n!=4);
}
















/*OUTPUT:-

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:1

Enter insertion value:1

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:1

Enter insertion value:2

Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:3

The items in the QUEUE are: 1  2
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:2

Deleted item is: 1
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:3

The items in the QUEUE are: 2
Choice are:
1: INSERTION
2: DELETION
3: DISPLAY ITEMS
4: EXIT
Enter your choice:4   */

No comments:

Post a Comment