/*************************************************************************/
/*Queu implementation Using Array[]*/
/*following are the header files*/
#include <iostream>
#include <conio>
#include <stdlib>
/*-----------------------------*/
#define max 5
/*********************************/
class cQueu
{
private:
int queu[max];
int front ,rear;
public:
cQueu();
~cQueu();
void insert();
void del();
void show();
};
cQueu::cQueu() /*Constructor*/
{
front=rear=-1;
} /*Distructor*/
cQueu::~cQueu()
{
cout<<"De-elocate the Memory\n";
} /*Defining a member function*/
void cQueu::insert()
{ if(front==-1 && rear==max-1)
{ front=rear+1;
cout<<"Queu is Overflow\n";
return ; }
if(front==-1)
front=rear=0;
else if(rear==max-1)
rear=0;
else
rear++;
cout<<"Enter element in Queu\t\t:";
cin>>queu[rear];
cout<<endl;
}
/**/
void cQueu::del()
{
if(front==-1)
{ cout<<"Queu is underflow\n";
return; }
cout<<" "<<queu[front]<<":\tHas been deleted\n";
if(front==rear)
front=rear=-1;
else if(front==max-1)
front=0;
else
front++;
} /***********************************/
void cQueu::show()
{ if(front==-1)
cout<<"Queu is Empty:\n";
else
{
for(int i=front; i<=rear; i++)
{ cout<<queu[i]<<" ";
}cout<<endl;
}
}
void main()
{ cQueu m;
int opt;
while(1)
{ cout<<" Main Menu \n";
cout<<" Enter 1 to enter element into Queu\n ";
cout<<" Enter 2 to delete element in the Queu\n";
cout<<" Enter 3 to show Queu elements \n";
cout<<" Enter 4 to Exit from the program\n";
cin>>opt;
switch(opt)
{case 1:m.insert();break;
case 2:m.del();break;
case 3:m.show();break;
case 4:exit(0);
}
}
getch();
}
0 comments:
Post a Comment