Thursday, July 9, 2009

How can I make a stack for strings in C++ without using templates?

you certainly could, don't see much of a use but a stack is a very simple container...so if you create a class (or a struct) called stringcontainer..or whatever





class stringContainer


{


private:


std::string sts [100 ] ;


int index;


public:


stringContainer()


{ index = 0;}


void push( string st){ sts[index] = st; index++; }


std::string pop ()


{ index--; return sts[index];}





};





check my syntax, i might have missed a semicolon, but you get the idea, you can make the constructor take a number to set the size of the stack...that is up to you

How can I make a stack for strings in C++ without using templates?
well the eziest way wud probly be to use inline assembly to push and pop things off the stack lol, but i assume u mean a higher level structure, anyways u just make an array of data, and an int that "points" to the item that is at the top, when u add to stack, raise the int, when u pop, lower it, it is really a simple data structure
Reply:hello, i have no clue what you are talking about man!


No comments:

Post a Comment