Sunteți pe pagina 1din 6

SCS_3285 PROGRAM TO PERFORM OPERATION IN DQUEUE #include<conio.h> #include<stdio.

h> #define max 3 int dqueue[max],front=-1,rear=-1,c,ch,i=0; void insertr( ); void deletr( ); void insertf( ); void deletf( ); void display( ); void main( ) { char s,a,b,m; clrscr ( ); do { printf("Enter the choice\n"); printf("1.Input restricted queue\n2.Output restricted queue\n"); scanf("%d",&c); switch(c) { case 1: do { printf("Enter the choice\n"); printf("1.Insertion\n2.Deletion from front\n3.Deletion from rear\n"); scanf("%d",&ch); switch(ch) { case 1: insertr( );break; case 2: deletf( );break; case 3: deletr( );break; default: printf("WRONG CHOICE\n"); } display( ); printf("Do u want to continue??(y/N)\n"); scanf(" %c",&a); }while((a=='Y')||(a=='y')); break; case 2: do{ printf("Enter the choice\n"); printf("1.Deletion\n2.Insertion to front\n3.Insertion to rear\n"); scanf("%d",&m); switch(m)

{ case 1: deletf( );break; case 2: insertf( );break; case 3: insertr( );break; default: printf("WRONG CHOICE\n"); } display( ); printf("Do u want to continue??(y/N)\n"); scanf(" %c",&b); }while((b=='Y')||(b=='y')); break; default: printf("WRONG CHOICE\n"); } printf("Do u want to return to main menu?(y/N)\n"); scanf(" %c",&s); }while((s=='Y')||(s=='y')); getch(); } void insertr( ) { if(rear==max-1) { rear=-1; } if(front==rear+1) { printf("Queue overflow\n"); } else { if(front==-1) { front=0; } rear++; printf("Enter the element to inserted\n"); scanf("%d",&dqueue[rear]); } } void insertf( ) { if(((front==0)&&(rear==max-1))||(front==rear+1)) { printf("Queue overflow\n"); }

else { if((front==-1)&&(rear==-1)) { front=0; rear=0; } else if(front==0) { front=max-1; } else { front--; } printf("Enter the element to be inserted\n"); scanf("%d",&dqueue[front]); } } void deletf( ) { if((front==-1)&&(rear==-1)) { printf("Queue underflow\n"); } else { printf("The element %d is deleted\n",dqueue[front]); if(front==rear) { front=-1; rear=-1; } else if(front==max-1) { front=0; } else { front++; } } } void deletr( ) { if((front==-1)&&(rear==-1)) { printf("Queue underflow\n"); } else

{ printf("The element %d is deleted\n",dqueue[rear]); if(front==rear) { front=-1; rear=-1; } else if(rear==0) { rear=max-1; } else { rear--; } } } void display( ) { printf("DQUEUE: "); if(front<=rear) { for(i=front;i<=rear;i++) { printf("%d ",dqueue[i]); } } else { for(i=0;i<=rear;i++) { printf("%d ",dqueue[i]); } for(i=front;i<=max-1;i++) { printf("%d ",dqueue[i]); } } printf("\n"); } OUTPUT Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 1 Enter the element to inserted 1 DQUEUE: 1

Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 1 Enter the element to inserted 2 DQUEUE: 1 2 Do u want to continue??(y/N) y Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 1 Enter the element to inserted 3 DQUEUE: 1 2 3 Do u want to continue??(y/N) y Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 2 The element 1 is deleted DQUEUE: 2 3 Do u want to continue??(y/N) y Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 3 The element 3 is deleted DQUEUE: 2 Do u want to continue??(y/N) y Enter the choice 1.Insertion 2.Deletion from front 3.Deletion from rear 1 Enter the element to inserted 5 DQUEUE: 2 5 Do u want to continue??(y/N) y Enter the choice 1.Insertion 2.Deletion from front

3.Deletion from rear 1 Enter the element to inserted 6 DQUEUE: 6 2 5 Do u want to continue??(y/N) n Do u want to return to main menu?(y/N) y Enter the choice 1.Input restricted queue 2.Output restricted queue 2 Enter the choice 1.Deletion 2.Insertion to front 3.Insertion to rear 1 The element 2 is deleted DQUEUE: 6 5 Do u want to continue??(y/N) y Enter the choice 1.Deletion 2.Insertion to front 3.Insertion to rear 1 The element 5 is deleted DQUEUE: 6 Do u want to continue??(y/N) y Enter the choice 1.Deletion 2.Insertion to front 3.Insertion to rear 1 The element 6 is deleted DQUEUE: Do u want to continue??(y/N) y Enter the choice 1.Deletion 2.Insertion to front 3.Insertion to rear 1 Queue underflow Do u want to continue??(y/N) n Do u want to return to main menu?(y/N) n

S-ar putea să vă placă și