Skip to content

Instantly share code, notes, and snippets.

@iKlsR
Created December 30, 2012 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iKlsR/4413478 to your computer and use it in GitHub Desktop.
Save iKlsR/4413478 to your computer and use it in GitHub Desktop.
a very very simple stack..
#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