/**********************************************************/
/*Queu implementation UsinG Linked list*/
/*Header files are!*/
#include <iostream>
#include <conio>
#include <stdlib>
/*Define a class */
class cQueu
{
private:
/*ABSTDT are!*/
struct node
{ int data;
node *link;
};
node *front;
node *rear;
public:
cQueu();
~cQueu();
void insert();
void del();
void show();
}; /*End of class */
/*Constructor is define*/
cQueu::cQueu()
{
front=rear=NULL;
}
/*Distructor is define*/
cQueu::~cQueu()
{
cout<<"Node are destoryed\n";
}
/*insert() function define here*/
void cQueu::insert()
{
node *t;
t=new node;
if(t==NULL)
cout<<"Overflow\n";
else
{
cout<<"Enter element\t";
cin>>t->data;
t->link=NULL;
if(rear==NULL)
rear=front=t;
else
{
rear->link=t;
}
}
} /*Defining delete function()*/
void cQueu::del()
{
node *n;
if(front==NULL)
cout<<"Under flow\n";
else
{
cout<<front->data<<"\t:"<<"Has been deleted\n";
n=front;
front=front->link;
delete n;
}
}
/*Defining show fun()*/
void cQueu::show()
{
if(front==NULL&& rear==NULL)
cout<<"Queu is empty\n";
else
{
while(rear!=NULL)
{cout<<rear->data<<" ";
cout<<endl;
rear=rear->link; }
}
}
/*Defining main function()*/
void main()
{
cQueu m;
int opt;
while(1)
{
cout<<"Press 1 to enter element in the Queu:\n";
cout<<"Press 2 to delete element in the Queu:\n";
cout<<"Press 3 to show the element of the Queu:\n";
cout<<"Press 4 to Exit the program from the main menu\n";
cin>>opt;
switch(opt)
{
case 1:m.insert();break;
case 2:m.del();break;
case 3:m.show();break;
case 4:exit(1);break;
case 5:cout<<"\b";
}
}
getch();}
0 comments:
Post a Comment