User is asked to Insert into.. Delete from or Display the entire queue..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<stdio.h>
- #include<conio.h>
- #include<process.h>
- int queue[5];
- long front,rear;
- void initqueue();
- void display();
- void main()
- {
- int choice,info;
- clrscr();
- while(1)
- {
- clrscr();
- printf(" MENU \n");
- printf("1.Insert an element in queue\n");
- printf("2.Delete an element from queue\n");
- printf("3.Display the queue\n");
- printf("4.Exit!\n");
- printf("Your choice: ");
- scanf("%i",&choice);
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- switch(choice)
- {
- case 1:if(rear<4)
- {
- printf("enter the number: ");
- scanf("%d",&info);
- if (front==-1)
- {
- front=0;
- rear=0;
- }
- else
- rear=rear+1;
- queue[rear]=info;
- }
- else
- printf("queue is full");
- getch();
- break;
- case 2: int info;
- if(front!=-1)
- {
- info=queue[front];
- if(front==rear)
- {
- front=-1;
- rear=-1;
- }
- else
- front=front+1;
- printf("no deleted is = %d",info);
- }
- else
- printf("queue is empty");
- getch();
- break;
- case 3: display();
- getch();
- break;
- case 4: exit(1);
- break;
- default:printf("You entered wrong choice!");
- getch();
- break;
- }
- }
- }
- void initqueue()
- {
- front=rear=-1;
- }
- void display()
- {
- int i;
- for(i=front;i<=rear;i++)
- printf("%i\n",queue[i]);
- }
1 comments:
It would be very helpful if you provide the code with syntax highlight feature.
Post a Comment