How do i rectify the following errors in c++ because i am not able to look and rectif

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danushnick
    New Member
    • Nov 2013
    • 1

    How do i rectify the following errors in c++ because i am not able to look and rectif

    The following errors are shown:
    1)50:identifier 'push' cannot have a type qualifier.
    2)147: declaration missing;
    3)147: compound statement missing ;
    4)147: compound statement missing ;

    Code:
    #include<iostream.h>
    #include<conio.h>
    class stack
    {
    private:
    struct node
    {
    int data;
    node *next;
    }*p;
    public:
    stack();
    void create(int numtot);
    int push();
    int pop();
    void display();
    ~stack();
    };
    stack::stack()
    {
    p=NULL;
    }
    void stack::create(int numtot)
    {
    node *temp,*rtr;
    rtr=new node;
    rtr=p;
    int num,i;
    for(i=0;i<numtot;i++)
    {
    if(p==NULL)
    {
    temp=new node;
    temp->data=num;
    temp->next=NULL;
    p=temp;
    }
    else
    {
    while(rtr->next!=NULL)
    {
    rtr=rtr->next;
    }
    temp=new node;
    temp->data=num;
    rtr->next=temp;
    temp->next=NULL;
    }
    int stack::push()
    {
    int num;
    cin>>num;
    s.create(num);
    s.display();
    return 0;
    }
    int stack::pop()
    {
    node *temp,*rtr;
    int item;
    rtr=new node;
    rtr=p;
    if(rtr==NULL)
    cout<<"Stack is full";
    return NULL;
    else
    {
    while(rtr!=NULL)
    {
    rtr=rtr->next;
    }
    temp=new node;
    temp=rtr;
    item=temp->data;
    rtr=rtr->next;
    delete temp;
    return item;
    }
    }
    void stack::display()
    {
    int *rtr;
    rtr=new node;
    rtr=p;
    if(rtr==NULL)
    cout<<"Stack is empty";
    else
    {
    while(rtr->next!=NULL)
    {
    cout<<"The elements are"<<rtr->data<<"/n";
    rtr=rtr->next;
    }
    }
    }
    stack::~stack()
    {
    node *temp;
    temp=new node;
    while(p->next!=null)
    {
    temp=p;
    p=p->next;
    delete temp;
    }
    }
    int main()
    {
    stack s;
    int numtot,ch,a;
    do
    {
    cout<<"Stack using link list"<<"/n";
    cout<<"_____________________"<<"/n";
    cout<<"1.Create"<<"/n";
    cout<<"2.Push"<<"/n";
    cout<<"3.Pop"<<"/n";
    cout<<"4.Display"<<"/n";
    cout<<"5.Exit"<<"/n";
    cout<<"Enter your choice:"
    cin>>ch;
    switch(ch)
    {
    case 1:
    cout<<"/n"<<"Enter the total numbers you are going to feed:";
    cin>>numtot;
    s.create(numtot);
    s.display();
    break;
    case 2:
    s.push();
    break;
    case 3:
    a=s.pop();
    s.display();
    break;
    case 4:
    s.display();
    break;
    default:
    break;
    }
    getch();
    }while(ch<5)
    return 0;
    }
Working...