template class

Discussion in 'Homework Help' started by manasa993, Aug 22, 2012.

  1. manasa993

    Thread Starter New Member

    Jun 28, 2012
    5
    0
    #include<iostream.h>
    #include<conio.h>

    template<class T>
    class queue{
    T n;
    public:

    queue *next;

    queue* enqueue(queue a)
    {
    queue* temp;

    temp=new queue;
    if(temp==NULL)
    cout<<"\nOVERFLOW!!!!";
    else
    {
    temp->n=a;
    temp->next=NULL;
    return temp;
    }
    return NULL;
    }

    queue* dequeue(queue *front)
    {
    queue* temp=front;

    if(temp==NULL)
    cout<<"\nUNDERFLOW!!!!";
    else
    {
    front=front->next;
    cout<<"\nELEMENT TO DEQUEUE:"<<temp->n;
    delete temp;
    return front;
    }
    return NULL;
    }

    void disp(queue *temp)
    {
    if(temp==NULL)
    cout<<"\nNO ELEMENTS EXSISTS!!!!";
    else
    {
    while(temp)
    {
    cout<<temp->n<<" ";
    temp=temp->next;
    }
    }
    }
    };

    void main()
    {
    clrscr();

    int n,a;
    queue *rear=NULL,*front=NULL,*temp;

    do{
    cout<<"\n\t\tMENU\n1.ENQUEUE\n2.DEQUEUE\n3.DISPLAY\n4.EXIT\nENTER YOUR CHOICE:";
    cin>>n;

    switch(n)
    {
    case 1:{
    cout<<"\nENTER ELEMENT TO ENQUEUE:";
    cin>>a;
    temp=rear->enqueue(a);
    if(temp)
    {
    if(rear==NULL&&front==NULL)
    rear=front=temp;
    else
    rear->next=temp;
    rear=temp;
    }
    break;
    }
    case 2:{
    front=front->dequeue(front);
    break;
    }
    case 3:{
    front->disp(front);
    break;
    }
    case 4:{
    cout<<"\nTHANK YOU!!!!";
    break;
    }
    default:{
    cout<<"\nWRONG CHOICE!!!!";
    break;
    }
    }
    }while(n!=4);

    getch();
    }






    error: line:66 invalid use of template 'queue'
    line 68 statement missing ;



    can you help me with creating template class with pointer objects

    thanks in advance
     
Loading...