For All Human Beings.......

Wednesday, November 21, 2007

Linked Queue : C++ Code

Struct NODE
{
int Data;
NODE *Next;
};

class Queue
{
NODE *Rear,*Front;

public:
Queue(){Rear=NULL;Front=NULL;}
Void Qinsert();
Void Qdelete();
Void Qdisplay();
~Queue();
};

_______________________________________________________________

void Queue::Qinsert()
{
NODE *Temp;
Temp=new NODE;
Cout<<”Data:”;
Cin>>Temp->Data;
Temp->Next=NULL;
If (Rear==NULL)
{
Rear=Temp;
Front=Temp;
}
else
{
Rear->Next=Temp;
Rear=Temp;
}
}

_______________________________________________________________

void Queue::Qdelete()
{
if (Front!=NULL)
{
NODE *Temp=Front;
Cout<<<”deleted/n”;
Front=Front->Next;
Delete Temp;
If (Front==NULL) Rear=NULL;
}
else
cout<<”Queue Empty..”;
}

_______________________________________________________________

void Queue::Qdisplay()
{
NODE *Temp=Front;
While(Temp!=NULL)
{
cout<
<Temp->Data;
Temp=Temp->Next;
}
}

_______________________________________________________________

void Queue::~Queue()//Destructer Function
{
while (Front!=NULL)
{
NODE *Temp=Front;
Front=Front->Next;
delete Temp;
}
}

_______________________________________________________________

void main()
{
Queue QU; char Ch;
do
{ … // Complete the main function

}while (Ch!=’Q’);
}

_______________________________________________________________

No comments: