NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

NevLabs

Under Construction

Saturday, January 7, 2012

Queue Implementation using Linked List in C++


#include<iostream.h>
#include<conio.h>
struct node
{
 int data;
 struct node *link;
};
class queue
{
 struct node *front,*rear,*ptr;
 public:
 queue(){
 rear=NULL;
 front=NULL;
 }
 void enqueue(int);
 void dqueue();
 void display();
};
  void queue::enqueue(int data)
{
  ptr=new node;
  if(rear==NULL)
   { front=ptr;
   }
   else
   {
    rear->link=ptr;
    ptr->link=NULL;
    }
    rear=ptr;
  rear->data=data;
  cout<<"\n>>";
      }
  void queue::dqueue()
{
int item;
 if(front==NULL)
 cout<<"\nQueue is empty:\n";
 else
 {
   item=front->data;
if(front==rear)
   {
   front=NULL;
   rear=NULL;
   }
else
{
   ptr=front;
   front=front->link;
   delete ptr;
   }
   cout<<"deleted elmnt : "<<item;
 }
}