Program 15
Click here to load reader
-
Upload
rishabh-bansal -
Category
Documents
-
view
217 -
download
1
description
Transcript of Program 15
PROGRAM 15
Date: 25/08/2015
Write a Menu Driven program to do insertion, deletion and display the elements in a Linear Circular Queue.
SOURCE CODE
#include<iostream.h>#include<conio.h>#include<stdio.h>#include<stdlib.h>struct student{
int rollno;char name[30];float marks;
};void enter(student S[], int i){
clrscr();
cout<<"ENTER ROLL NUMBER :- ";cin>>S[i].rollno;cout<<"ENTER NAME :- ";gets(S[i].name);cout<<"ENTER MARKS :- ";cin>>S[i].marks;
}void display(student S[], int j){
cout<<S[j].rollno<<" "<<S[j].name<<" "<<S[j].marks<<endl;}void insert_cq(student S[], int n , int&rear , int &front){
clrscr();
if((rear==n-1 &&front==0) || (rear==front+1)){
cout<<"QUEUE FULL ";}else if(rear==-1){
rear++; front=0;enter(S,rear);
}else{
rear++;enter(S,rear);
}
}void deletion(student S[], int n, int &rear , int &front){
if(front==-1){
cout<<"QUEUE IS EMPTY";}else if(rear==front){ display(S,front); front=-1; rear=-1;
}else if(front==n-1){
display(S,front);front=0;
}else{
display(S,front);front++;
}}void display_cq(student S[], int n, int rear, int front){
clrscr();if(front==-1){
cout<<"Queue is Empty";}else if(front<=rear){
for(int i=0; i<=rear; i++){
display(S,i);}
}else{
for(int i=front; i<n; i++)display(S,i);
for(int j=0; j<=rear; j++)display(S,j);
}}void main(){
clrscr();
student S[20]; int n,rear=-1,front=-1;
cout<<"Enter the number of students :- ";cin>>n;
clrscr();
int choice=0;
while(choice!=4){
clrscr();
gotoxy(3,3);cout<<"CIRCULAR QUEUE OPERATION";gotoxy(4,4);cout<<"1. INSERT";gotoxy(5,5);cout<<"2. DELETE";gotoxy(6,6);cout<<"3. DISPLAY ";gotoxy(7,7);cout<<"4. EXIT";
gotoxy(4,8);cout<<"Enter your Choice :- ";cin>>choice;
switch(choice){
case 1:clrscr();insert_cq(S,n,rear,front);getch();break;
case 2:clrscr();deletion(S,n,rear,front);getch();break;
case 3:clrscr();display_cq(S,n,rear,front);getch();break;
case 4:clrscr();cout<<"TERMINATING PROGRAM";exit(0);break;
default:cout<<"INVALID CHOICE";getch();
}}getch();
}
OUTPUT
e