Created
December 30, 2012 16:01
-
-
Save iKlsR/4413478 to your computer and use it in GitHub Desktop.
a very very simple stack..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
template <class _st> class stack { | |
public: | |
stack(); | |
void push(_st i); | |
_st pop(); | |
private: | |
int top; | |
_st sta[100]; | |
}; | |
template <class _st> stack<_st>::stack() { | |
top = -1; | |
} | |
template <class _st> void stack<_st>::push(_st i) { | |
sta[++top] = i; | |
} | |
template <class _st> _st stack<_st>::pop() { | |
return sta[top--]; | |
} | |
int main(int argc, char * argv[]) { | |
stack<int> my_int_stack; | |
my_int_stack.push(10); | |
stack<string> my_str_stack; | |
my_str_stack.push("foo"); | |
my_str_stack.push("var"); | |
my_str_stack.pop(); | |
cin.get(); | |
return 0x00; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment