[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


implementation of stack using operator overloading in c++ &...

<< Back to: LEARN C/C++ TODAY (A list of resources/tutorials)

Question by parimala
Submitted on 12/8/2003
Related FAQ: LEARN C/C++ TODAY (A list of resources/tutorials)
Rating: Rate this question: Vote
implementation of stack using operator overloading in c++ & overloading << operator too.


Answer by rareddy77
Submitted on 3/3/2005
Rating: Not yet rated Rate this answer: Vote
c++ progam files

 

Answer by j0hn_galt
Submitted on 4/22/2005
Rating: Not yet rated Rate this answer: Vote
its pretty easy. you could overload '+' to push and operator '-' to pop in the class Stack. here's the code for it:

class stack {
    int S[5];
    int tos;
    public:
        stack(){tos=0;}
        void operator+(int i);
        void operator-();
        }stkobj;
    
    void stack::operator+(int i)
    {
        if(tos==4)
        {
            cout<<"stack is full\n";
            return;
        }
        else
        {
            stkobj.S[tos++]=i;
            return;
        }
    }
    
    void stack::operator-()
    {
        if(tos==-1)
        {
            cout<<"stack is empty\n";
            return;
        }
        else
        {
            int j;
            j=stkobj.S[tos];
            cout<<"popped "<<j<<endl;
            stkobj.S[tos]=0;
            tos--;
            return;
        }
    }

for displaying the contents of the stack you could overload '<<'. using the built-in  output classes      

 

Answer by Nani
Submitted on 9/13/2005
Rating: Not yet rated Rate this answer: Vote
Its gud

 

Answer by aishwarya
Submitted on 12/8/2005
Rating: Not yet rated Rate this answer: Vote
implementation of stack using operator overloading in c++ & overloading << operator too.

 

Answer by viv
Submitted on 1/20/2006
Rating: Not yet rated Rate this answer: Vote
money

 

Answer by Sekhar
Submitted on 9/11/2006
Rating: Not yet rated Rate this answer: Vote
sekhar

 

Answer by ravi
Submitted on 1/18/2007
Rating: Not yet rated Rate this answer: Vote
ravi rayappan

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: LEARN C/C++ TODAY (A list of resources/tutorials)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.