یاس
12-01-2008, 12:22 PM
#include<iostream.h>
#include<conio.h>
int q[5];
int front,rear;
void main()
{
void add(int);
int del();
int will=1,a,num;
front=0;
rear=0;
clrscr();
while(will==1)
{
cout<<"main menu"<<endl<<"1.add"<<endl<<"2.del"<<"0.exit"<<endl;
cin>>will;
switch(will)
{
case 1:
cout<<"enter the data ...";
cin>>num;
add(num);
break;
case 2:
i=del();
cout<<"value returned from delete function is :"<<i<<endl;
break;
default :
cout<<"error ! try again.."<<endl;
}
cout<<" do you want to do more operation on Queue";
cout<<"(press 1 for yes ,any key to exit )";
cin>>will;
}/* end while */
}/*end main */
void add(int a)
{
if (rear==5)
rear=1;
else
rear=rear+1;
if(front==rear)
cout<<"queue is full "; else{
q[rear]=a; rear++;
cout<<"valye of rear:"<<rear<<" and front is :"<< front<<endl;
}
}
int del()
{
int a;
if(front==rear)
{
cout<<"queue is empty! ";
return(0);
}
else
{
if(front==5)
front=1;
else
{front++;
a=q[front];}
}
return(a);
}
#include<conio.h>
int q[5];
int front,rear;
void main()
{
void add(int);
int del();
int will=1,a,num;
front=0;
rear=0;
clrscr();
while(will==1)
{
cout<<"main menu"<<endl<<"1.add"<<endl<<"2.del"<<"0.exit"<<endl;
cin>>will;
switch(will)
{
case 1:
cout<<"enter the data ...";
cin>>num;
add(num);
break;
case 2:
i=del();
cout<<"value returned from delete function is :"<<i<<endl;
break;
default :
cout<<"error ! try again.."<<endl;
}
cout<<" do you want to do more operation on Queue";
cout<<"(press 1 for yes ,any key to exit )";
cin>>will;
}/* end while */
}/*end main */
void add(int a)
{
if (rear==5)
rear=1;
else
rear=rear+1;
if(front==rear)
cout<<"queue is full "; else{
q[rear]=a; rear++;
cout<<"valye of rear:"<<rear<<" and front is :"<< front<<endl;
}
}
int del()
{
int a;
if(front==rear)
{
cout<<"queue is empty! ";
return(0);
}
else
{
if(front==5)
front=1;
else
{front++;
a=q[front];}
}
return(a);
}