Queue implementation using linked list


#include<iostream.h>

#include<string.h>

#include<iomanip.h>

#include<stdio.h>

 

 

 

class item

{

public:

 

      int number;

};

 

 

class container

{

public:

 

      container();

     

      void Enqueue(int x);

      void remove(item &);

      void find (int );

      void Dequeue();

      bool IsFull();

      bool IsEmpty();

 

private:

      item itm;

 

      container *tail;

      container *head;

      container *next;

      int currentSize;

 

};

 

container::container()

{

            head=NULL;

 

            tail=head;

 

            next=NULL;

 

            counter=0;

 

            currentSize=0;

 

     

}

 

bool container::IsFull()

{

      container *temp=new container;

 

      if(!temp)           //p is not alloctaed any memory

            return true;

 

      else

            delete temp;

 

            return false;

}

 

bool container::IsEmpty()

{

      return head==NULL;

}

 

 

void container::Enqueue(int x)

{

      if(!IsFull())

      {

            currentSize++;

  

      container *temp=new container;

     

          temp->itm.number=x;

        

           

            if(IsEmpty())

            {    

                  head=tail=temp;

            }

            else

            {

                 

 

                 

                  tail->next=temp;

                  tail=tempp;

                 

            }

     

      }

      else

            cout<<"queue full"<<endl;

}

 

void container::Dequeue()

{

      if(!IsEmpty())

      {

            container *tempy=new container;

           

            if(head==tail)

            {

                  tempy=head;

                  head=tail=NULL;

                  cout<<tempy->itm.number<<endl;

currentsize--;

            }

            else

            {

                 

                  tempy=head;

                  head=head->next;

       

                  cout<<tempy->itm.number<<endl;

                  delete tempy;

currentsize--;

            }

     

           

      }

      else

            cout<<"Queue is  empty!"<<endl;

}

 

 

void container::find(int num)

{

      container *p;

      p=head;

 

      while(p->itm.number!=num)

      {

            p=p->next;

      }

 

      if(p->itm.number==num)

      {

            cout<<"num: "<<p->itm.number<<endl;

      }

 

      else

            cout<<"not found"<<endl;

 

}