Download - Queue Formatted program widout algorithm
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 1/7
Algorithm and Programming forQUEUE USING C PROGRAMMING
PROGRAM : #include<stdio.h.>
#include<conio.h>
#define MAXSIZE 10
struct st
{
int front,rear;
int queue[MAXSIZE];
};
struct st s;
int empty(void);
int full(void);
void add(void);void delete(void);
void display(void);
void main()
{
char ans;
int ch;
s.front = 0;
s.rear = 0;
do
{
clrscr();
printf("********Queue Program**********\n");
printf("1. ADD\n");
printf("2. DELETE\n");
printf("3. DISPLAY\n");
printf("4. QUIT\n");
printf("Enter Your Choice : ");
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 2/7
scanf("%d",&ch);
switch(ch)
{
case 1:
add();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
break;
default:
printf("INVALID CHOICE!!!!!!!!!!!!!!!!\n");
break;
}
printf("\nWant To Go To The Main Menu[y/n]");
flushall();
ans = getch();
}
while(ans == 'y' ans == 'Y');
printf("\nPress Any Key To Continue\n");
getch();
}
int full(void){
if (s.rear == MAXSIZE)
return(1);
else
return(0);
}
int empty(void)
{
if (s.front == s.rear + 1)
return(1);
elsereturn(0);
}
void add(void)
{
char ch;
int x;
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 3/7
do
{
if(full() == 1)
{
printf("\n\nQueue Full\n");
break;
}
else
{
s.rear = s.rear + 1;
printf("\nEnter An Element to Be Added ");
scanf("%d",&x);
s.queue[s.rear] = x;
if(s.rear == 1) s.front ++;
}
printf("\nDo You Want to Add More Elements[y/n]:");
flushall();
ch = getch();
}
while(ch=='y' ch == 'Y');
}
void delete(void)
{
char ch;
do
{
if(empty() == 1)
{printf("\n\nQueue Empty\n");
break;
}
else
{
printf("% d Has Been Deleted!",s.queue[s.front]);
s.front = s.front +1;
}
printf("\nWant to Delete More [y\n]");
flushall();
ch = getch();}
while(ch=='y' ch == 'Y');
}
void display(void)
{
int i;
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 4/7
clrscr();
if(empty () == 1)
printf("\nQueue Empty!!");
else
{
printf("\nDisplaying Queue\n");
for(i = s.front;i printf("%d\n",s.queue[i]);
}
}
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 5/7
OUTPUT: Queue Program: 1. ADD
2. DELETE
3. DISPLAY
4. QUIT
Enter Your Choice : 1
Enter An Element to Be Added 1
Do You Want to Add More Elements[y/n]:y
Enter An Element to Be Added 2
Do You Want to Add More Elements[y/n]:y
Enter An Element to Be Added 3
Do You Want to Add More Elements[y/n]:y
Enter An Element to Be Added 4
Do You Want to Add More Elements[y/n]:y
Enter An Element to Be Added 5
Do You Want to Add More Elements[y/n]:n
Want To Go To The Main Menu[y\n] y
Queue Program: 1. ADD
2. DELETE3. DISPLAY
4. QUIT
Enter Your Choice : 3
Displaying Queue
1
2
3
4
5
Want To Go To The Main Menu[y\n] y
Queue Program: 1. ADD
2. DELETE
3. DISPLAY
4. QUIT
Enter Your Choice : 2
8/3/2019 Queue Formatted program widout algorithm
http://slidepdf.com/reader/full/queue-formatted-program-widout-algorithm 6/7
1 Has Been Deleted!!
Do You Want To Delete More?[y/n] n
Want to Go To Main Menue[y/n] y
Queue Program:
1. ADD2. DELETE
3. DISPLAY
4. QUIT
Enter Your Choice : 3
Displaying Queue
2
3
4
5
Want To Go To The Main Menu[y\n] y
Queue Program: 1. ADD
2. DELETE
3. DISPLAY
4. QUIT
Enter Your Choice : 4