#include <iostream>
using namespace std;
/*
2,3
*/
template <class T>
class MyStack {
private:
int tos;
T data[100];
public:
MyStack();
void push(T element);
T pop();
};
template<class T>
MyStack<T>::MyStack() {
tos = -1;
}
template<class T>
void MyStack<T>::push(T element) {
if (tos == 99) {
cout << "stack full";
return;
}
tos++;
data[tos] = element;
}
template<class T>
T MyStack<T>::pop() {
T retData;
if (tos == -1) {
cout << "stack empty";
return 0;
}
else {
retData = data[tos--];
return retData;
}
}
class Point {
int x, y;
public:
Point(int x = 0, int y = 0) {
this->x = x, this->y = y;
}
void show() { cout << x << ',' << y << endl; }
};
int main() {
MyStack<Point> pointStack;
Point a(2, 3), b;
pointStack.push(a);
b = pointStack.pop();
b.show();
}
STL(Standard Template Library)
STL의 구성
반족자의 종류