/* 4. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ½á¶ó. */ #include int number[5] = { 1, 2, 3, 4, 5 }; // ¿©±â¸¦ ¹Ù²Ü °Í class Stack { int n; int *x; public: Stack() { n = 96; x = new int[n]; for(int i = 0; i < n; i++) x[i] = 0; } void push(int data) { for(int pos = n-1; pos >= 0; pos--) { if (x[pos] == 0) { x[pos] = data; break; // ÀÌ for ·çÇÁ¸¦ ºüÁ®³ª°¨ } } int m = n / 2; int *y = new int[m]; for(int i = n-1; i >= m; i--) { y[i-m] = x[i]; } x = y; n = m; } void pop() { x[0] = 0; } void print() { for(int i = 0; i < n; i++) printf("%d ",x[i]); putchar('\n'); } }; void main() { Stack test; test.push(number[0]); test.pop(); test.push(number[1]); test.push(number[2]); test.push(number[3]); test.push(number[4]); test.pop(); test.print(); }