Sunday, July 4, 2010

PROGRAM TO ILLUSTRATE QUEUE OPERATION USING ARRAY(DS)

Buzz It
#include<iostream.h>
#include<conio.h>
class queue
{
int a[100],size,front,rear,i;
public:
void insertion();
void getsize();
void deletion();
void display();
};
void queue::getsize()
{
cout<<"enter the max size\n";
cin>>size;
front=rear=0;
}
void queue::insertion()
{
if(rear==size)
{
cout<<"over flow\n";
}
else
{
cout<<"enter data\n";
cin>>a[rear];
rear++;
}}
void queue::deletion()
{
if(front==rear)
{
cout<<"under flow\n";
front=rear=0;
}
else
{
front++;
}}
void queue::display()
{
cout<<'the elements in the array \n";
for(i=front;i<rear;i++)
cout<<a[i]<<"\t";
}
void main()
{
int c;
clrscr();
queue ob;
ob.getsize();
do
{
cout<<"\nmenu\n1-insertion\n2-deletion\n3-display\n4-exit\n";
cin>>c;
switch(c)
{
case 1:ob.insertion();
break;
case 2:ob.deletion();
break;
case 3:ob.display();
break;
}}
while(c<=3);
getch();
}


OUTPUT:
enter max size
2
menu
1-insertion
2-deletion
3-display
4-exit
1
enter data
58
menu
1-insertion
2-deletion
3-display
4-exit
1
enter data
67
menu
1-insertion
2-deletion
3-display
4-exit
3
the elements in the array
58 67
menu
1-insertion
2-deletion
3-display
4-exit
1
overflow
menu
1-insertion
2-deletion
3-display
4-exit
2
menu
1-insertion
2-deletion
3-display
4-exit
3
the elements in the array
67
menu
1-insertion
2-deletion
3-display
4-exit
2
menu
1-insertion
2-deletion
3-display
4-exit
2
underflow
menu
1-insertion
2-deletion
3-display
4-exit


0 comments:

Post a Comment