/* Priorities Queu implementation */
/*Header files are define As*/
#include <iostream>
#include <conio>
#include <stdlib>
/*Defining a class */
class cQueu
{
public:
cQueu();
~cQueu();
void insert();
void del();
private:
struct node
{int data;
int pr;
node *link;};
node *front ;
};
/*Ending of class */
cQueu::cQueu()
{
front =NULL;
}
/*Distructor*/
cQueu::~cQueu()
{
cout<<"UR program End and ur data will be lose";
}
/*Defining a member function void insert()*/
void cQueu::insert()
{
node *n=front,*p=NULL,*t;
t=new node ;
if(t==NULL)
cout<<"\t\t\tOVER_FLOW\n";
else
{
cout<<"\tEnter element in Queu:\t";
cin>>t->data;
cout<<"\tEnter priority\t:";
cin>>t->pr;
if(front==NULL)
{t->link=NULL;
front=t; }
else
{
while((n->pr>=t->pr)&&(n!=NULL))
{ p=n;
n=n->link;}
if(p==NULL)
{t->link=front;
front=t;
}
else
{
t->link=p->link;
p->link=t;
} }}
}
/**DElete function ()*/
void cQueu::del()
{
node *n;
if(front==NULL)
cout<<"\t\t\tUndr flow\n";
else
{cout<<front->data<<":\tWith priority\t:"<<front->pr<<"\tDeleted\n";
n=front;
front=front->link;
delete n;
}
}
void main()
{ cQueu m;
int opt;
while(1)
{
cout<<"\t\t1:Insert element into Queu:\n";
cout<<"\t\t2:Delete element from the Queu\n";
cout<<"\t\t3:Exit\n";
cout<<"\t\t4:PRSS 4 KEY TO CLEAR SCREEN\n";
cin>>opt;
switch(opt)
{ case 1:m.insert(); break;
case 2:m.del();break;
case 3:exit(0);break;
case 4: clrscr();break;
}
}
getch();}
0 comments:
Post a Comment