// ÁÖ°£¿ë 2¹ø ¹®Á¦ #include #define NIL (0) class Stack { int *_s; int *_top; public: Stack(int n) { _s = new int[10*n]; _top = _s; for(int i = 0; i < 10*n; i++) { *(_s+i) = -1; } } void push(int x) { int y = x/3*3; if (y == x) { *_top = x; _top++; *_top = x; _top++; *_top = x; _top++; } else if (y+2 == x) { *_top = x; _top++; *_top = x; _top++; } else if (y+1 == x) { *_top = x; _top++; } } int pop(int x) { return *_top; } void print() { while (*_s != -1) { printf("%d",*_s); _s++; } printf("\n"); } }; void main() { int data[5] = { 0, 1, 2, 3, 4 }; Stack x(5); for(int i = 0; i < 5; i++) { x.push(data[i]); x.pop(data[i]); } x.print(); }