SlideShare a Scribd company logo
5. Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
b. Solving Tower of Hanoi problem with n disks.
#include<stdio.h>
#include<conio.h>
#define MAX 20 struct
stack
{
int top;
int str[MAX];
}s;
charpostfix[MAX];
int pop();
intisoperand(char);
intoperate(int,int,char); int
main()
{
int i=0;
intans,op1,op2;
clrscr();
s.top=-1;
printf("Enter a VALID POSTFIX Expression:"); scanf("%s",postfix);
while(postfix[i]!='0')
{
if(isoperand(postfix[i]))
push(postfix[i]-48);
else
{
} i++;
}
op1=pop();
op2=pop();
ans=operate(op1,op2,postfix[i]);
push(ans);
printf("%d %c %d = %dn",op2,postfix[i],op1,ans);
printf("Answer=%d",s.str[s.top]); getch();
return;
}
int isoperand(char x)
{
if(x>='0' && x<='9')
return 1;
else
}
return 0;
void push(int x)
{
if(s.top==MAX-1)
{
}
else
}
printf("Enter expression < 20 charn");
getch();
exit(0);
s.str[++s.top]=x;
int pop()
{
if(s.top==-1)
{
}
else
}
printf("INVALIDPOSTFIXEXPRESSIONn");
getch();
exit(0);
returns.str[s.top--]
int operate(int op1,int op2,char a)
{
switch(a)
{
case '+':return op2+op1;
case '-':return op2-op1;
case '*':return op2*op1;
case '/':return op2/op1;
case '%':return op2%op1;
case '^':return pow(op2,op1);
}
return 0;
}
B) Tower of hanoi
#include <stdio.h>
#include<conio.h>
void towers(int, char, char, char);
int main()
{
int num;
clrscr();
printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :n"); towers(num, 'A', 'C', 'B');
getch();
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("n Move disk %d from peg %c to peg %c", num, frompeg, topeg); towers(num - 1, auxpeg, topeg,
frompeg);
}
6.Design, Develop and Implement a menu driven Program in C for the following operations on Circular
QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit.
Support the program with appropriate functions for each of the above operations
#include <stdio.h>
#include<conio.h>
#define MAXSIZE 5
int cq[MAXSIZE]={0};
int front,rear;
void insert(int);
void del();
void display();
void main()
{
int ch,i,num;
front = -1;
rear = -1;
clrscr();
printf("nProgram for Circular Queue demonstration through array");
for(;;)
{
printf("nnMAIN
MENUn1.INSERTIONn2.DELETIONn3.DISPLAYn4.EXIT");
printf("nnENTER YOUR CHOICE : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("nnENTER THE QUEUE ELEMENT : ");
scanf("%d",&num);
insert(num);
break;
case 2: del();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("nnInvalid Choice.");
}
}
}
void insert(int item)
{
if(front ==(rear+1)%MAXSIZE)
{
}
else
{
printf("nnCIRCULAR QUEUE IS OVERFLOW");
if(front==-1)
front=rear=0;
else
rear=(rear+1)%MAXSIZE;
front);
}
cq[rear]=item;
printf("n Circular Queue Status:Rear = %d Front = %d ",rear ,
}
void del()
{
int a;
if(front == -1)
{
}
else
{
printf("nnCIRCULAR QUEUE IS UNDERFLOW");
a=cq[front];
cq[front]=0;
if(front==rear)
front=rear=-1;
else
front = (front+1)%MAXSIZE;
printf("nDELETED ELEMENT FROM QUEUE IS : %d ",a);
printf("nCircular Queue Status:Rear = %dFront = %d ",rear,front);
}
}
void display()
{
int i;
if(front==-1&&rear==-1)
{
}
else
{
printf("Queue is underflown");
for(i=0; i<MAXSIZE; i++)
printf("%dt", cq[i]);
}
}
prg5,6,.doc computer science and engineering
Ad

More Related Content

Similar to prg5,6,.doc computer science and engineering (20)

Struct examples
Struct examplesStruct examples
Struct examples
mondalakash2012
 
pattern-printing-in-c.pdf
pattern-printing-in-c.pdfpattern-printing-in-c.pdf
pattern-printing-in-c.pdf
RSathyaPriyaCSEKIOT
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
program 4.doc in computer science and engineering
program 4.doc in computer science and engineeringprogram 4.doc in computer science and engineering
program 4.doc in computer science and engineering
SUNITHAS81
 
In C Programming- Create a program that converts a number from decimal.docx
In C Programming- Create a program that converts a number from decimal.docxIn C Programming- Create a program that converts a number from decimal.docx
In C Programming- Create a program that converts a number from decimal.docx
mckerliejonelle
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
mustkeem khan
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
C Programming lab
C Programming labC Programming lab
C Programming lab
Vikram Nandini
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
dalipkumar64
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
AAlha PaiKra
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
FOREVERPRODUCTCHD
 
Circular queue
Circular queueCircular queue
Circular queue
ShobhaHiremath8
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
week-3x
week-3xweek-3x
week-3x
KITE www.kitecolleges.com
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
Manoj Chauhan
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
program 4.doc in computer science and engineering
program 4.doc in computer science and engineeringprogram 4.doc in computer science and engineering
program 4.doc in computer science and engineering
SUNITHAS81
 
In C Programming- Create a program that converts a number from decimal.docx
In C Programming- Create a program that converts a number from decimal.docxIn C Programming- Create a program that converts a number from decimal.docx
In C Programming- Create a program that converts a number from decimal.docx
mckerliejonelle
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
mustkeem khan
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
dalipkumar64
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
FOREVERPRODUCTCHD
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
Mahmud Hasan Tanvir
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
Manoj Chauhan
 

Recently uploaded (20)

Fractures In Chronic Kidney Disease Patients - Copy (3).pptx
Fractures In Chronic Kidney Disease Patients - Copy (3).pptxFractures In Chronic Kidney Disease Patients - Copy (3).pptx
Fractures In Chronic Kidney Disease Patients - Copy (3).pptx
ChaitanJaunky1
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC
 
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
Nguyễn Minh
 
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
Taqyea
 
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
emestica1
 
34 E-commerce - business, technology and society (2022).pdf
34 E-commerce - business, technology and society (2022).pdf34 E-commerce - business, technology and society (2022).pdf
34 E-commerce - business, technology and society (2022).pdf
Nguyễn Minh
 
IoT PPT introduction to internet of things
IoT PPT introduction to internet of thingsIoT PPT introduction to internet of things
IoT PPT introduction to internet of things
VaishnaviPatil3995
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
Internet Coordination Policy 2 (ICP-2) Review
Internet Coordination Policy 2 (ICP-2) ReviewInternet Coordination Policy 2 (ICP-2) Review
Internet Coordination Policy 2 (ICP-2) Review
APNIC
 
34 Mobile Payment (Thomas Lerner (auth.).pdf
34 Mobile Payment (Thomas Lerner (auth.).pdf34 Mobile Payment (Thomas Lerner (auth.).pdf
34 Mobile Payment (Thomas Lerner (auth.).pdf
Nguyễn Minh
 
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
Taqyea
 
Cloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptxCloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptx
marketing140789
 
34 Advances in Mobile Commerce Technologies (2003).pdf
34 Advances in Mobile Commerce Technologies (2003).pdf34 Advances in Mobile Commerce Technologies (2003).pdf
34 Advances in Mobile Commerce Technologies (2003).pdf
Nguyễn Minh
 
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
Nguyễn Minh
 
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
Nguyễn Minh
 
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptxBiochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
SergioBarreno2
 
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
Breaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdfBreaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdf
Internet Bundle Now
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Fractures In Chronic Kidney Disease Patients - Copy (3).pptx
Fractures In Chronic Kidney Disease Patients - Copy (3).pptxFractures In Chronic Kidney Disease Patients - Copy (3).pptx
Fractures In Chronic Kidney Disease Patients - Copy (3).pptx
ChaitanJaunky1
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC Policy Update and Participation, presented at TWNIC 43rd IP Open Policy...
APNIC
 
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
34 E-commerce and M-commerce technologies (P. Candace Deans 2006).pdf
Nguyễn Minh
 
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
学生卡英国RCA毕业证皇家艺术学院电子毕业证学历证书
Taqyea
 
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
CompTIA-Security-Study-Guide-with-over-500-Practice-Test-Questions-Exam-SY0-7...
emestica1
 
34 E-commerce - business, technology and society (2022).pdf
34 E-commerce - business, technology and society (2022).pdf34 E-commerce - business, technology and society (2022).pdf
34 E-commerce - business, technology and society (2022).pdf
Nguyễn Minh
 
IoT PPT introduction to internet of things
IoT PPT introduction to internet of thingsIoT PPT introduction to internet of things
IoT PPT introduction to internet of things
VaishnaviPatil3995
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
Internet Coordination Policy 2 (ICP-2) Review
Internet Coordination Policy 2 (ICP-2) ReviewInternet Coordination Policy 2 (ICP-2) Review
Internet Coordination Policy 2 (ICP-2) Review
APNIC
 
34 Mobile Payment (Thomas Lerner (auth.).pdf
34 Mobile Payment (Thomas Lerner (auth.).pdf34 Mobile Payment (Thomas Lerner (auth.).pdf
34 Mobile Payment (Thomas Lerner (auth.).pdf
Nguyễn Minh
 
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
美国文凭明尼苏达大学莫里斯分校毕业证范本UMM学位证书
Taqyea
 
Cloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptxCloud-to-cloud Migration presentation.pptx
Cloud-to-cloud Migration presentation.pptx
marketing140789
 
34 Advances in Mobile Commerce Technologies (2003).pdf
34 Advances in Mobile Commerce Technologies (2003).pdf34 Advances in Mobile Commerce Technologies (2003).pdf
34 Advances in Mobile Commerce Technologies (2003).pdf
Nguyễn Minh
 
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
34 Global Mobile Commerce_ Strategies, Implementation and Case Studies (Premi...
Nguyễn Minh
 
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
34 Turban Electronic Commerce 2018_ A Managerial and Social Networks Perspect...
Nguyễn Minh
 
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptxBiochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
Biochemistry and Biomolecules - Science - 9th Grade _ by Slidesgo.pptx
SergioBarreno2
 
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
Breaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdfBreaking Down the Latest Spectrum Internet Plans.pdf
Breaking Down the Latest Spectrum Internet Plans.pdf
Internet Bundle Now
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Ad

prg5,6,.doc computer science and engineering

  • 1. 5. Design, Develop and Implement a Program in C for the following Stack Applications a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^ b. Solving Tower of Hanoi problem with n disks. #include<stdio.h> #include<conio.h> #define MAX 20 struct stack { int top; int str[MAX]; }s; charpostfix[MAX]; int pop(); intisoperand(char); intoperate(int,int,char); int main() { int i=0; intans,op1,op2; clrscr(); s.top=-1; printf("Enter a VALID POSTFIX Expression:"); scanf("%s",postfix); while(postfix[i]!='0') { if(isoperand(postfix[i])) push(postfix[i]-48); else { } i++; } op1=pop(); op2=pop(); ans=operate(op1,op2,postfix[i]); push(ans); printf("%d %c %d = %dn",op2,postfix[i],op1,ans); printf("Answer=%d",s.str[s.top]); getch(); return; }
  • 2. int isoperand(char x) { if(x>='0' && x<='9') return 1; else } return 0; void push(int x) { if(s.top==MAX-1) { } else } printf("Enter expression < 20 charn"); getch(); exit(0); s.str[++s.top]=x; int pop() { if(s.top==-1) { } else } printf("INVALIDPOSTFIXEXPRESSIONn"); getch(); exit(0); returns.str[s.top--] int operate(int op1,int op2,char a) { switch(a) { case '+':return op2+op1; case '-':return op2-op1; case '*':return op2*op1; case '/':return op2/op1; case '%':return op2%op1; case '^':return pow(op2,op1); } return 0; }
  • 3. B) Tower of hanoi #include <stdio.h> #include<conio.h> void towers(int, char, char, char); int main() { int num; clrscr(); printf("Enter the number of disks : "); scanf("%d", &num); printf("The sequence of moves involved in the Tower of Hanoi are :n"); towers(num, 'A', 'C', 'B'); getch(); return 0; } void towers(int num, char frompeg, char topeg, char auxpeg) { if (num == 1) { printf("n Move disk 1 from peg %c to peg %c", frompeg, topeg); return; } towers(num - 1, frompeg, auxpeg, topeg); printf("n Move disk %d from peg %c to peg %c", num, frompeg, topeg); towers(num - 1, auxpeg, topeg, frompeg); }
  • 4. 6.Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue with maximum size MAX) a. Insert an Element on to Circular QUEUE b. Delete an Element from Circular QUEUE c. Demonstrate Overflow and Underflow situations on Circular QUEUE d. Display the status of Circular QUEUE e. Exit. Support the program with appropriate functions for each of the above operations #include <stdio.h> #include<conio.h> #define MAXSIZE 5 int cq[MAXSIZE]={0}; int front,rear; void insert(int); void del(); void display(); void main() { int ch,i,num; front = -1; rear = -1; clrscr(); printf("nProgram for Circular Queue demonstration through array"); for(;;) { printf("nnMAIN MENUn1.INSERTIONn2.DELETIONn3.DISPLAYn4.EXIT"); printf("nnENTER YOUR CHOICE : "); scanf("%d",&ch); switch(ch) { case 1: printf("nnENTER THE QUEUE ELEMENT : "); scanf("%d",&num); insert(num); break; case 2: del(); break; case 3: display(); break; case 4: exit(0); default: printf("nnInvalid Choice."); } } }
  • 5. void insert(int item) { if(front ==(rear+1)%MAXSIZE) { } else { printf("nnCIRCULAR QUEUE IS OVERFLOW"); if(front==-1) front=rear=0; else rear=(rear+1)%MAXSIZE; front); } cq[rear]=item; printf("n Circular Queue Status:Rear = %d Front = %d ",rear , } void del() { int a; if(front == -1) { } else { printf("nnCIRCULAR QUEUE IS UNDERFLOW"); a=cq[front]; cq[front]=0; if(front==rear) front=rear=-1; else front = (front+1)%MAXSIZE; printf("nDELETED ELEMENT FROM QUEUE IS : %d ",a); printf("nCircular Queue Status:Rear = %dFront = %d ",rear,front); } } void display() { int i; if(front==-1&&rear==-1) { } else { printf("Queue is underflown"); for(i=0; i<MAXSIZE; i++) printf("%dt", cq[i]); } }