#include #include #include #include #include #define STACK_MAX 10 typedef int StackData; int nStackCounter; int Stack[STACK_MAX]; void StackInitialize(); bool isEmpty(); bool isFull(); void push(StackData); void pop(); void PrintStack(); void main() { int nSelect; StackData nStackData; StackInitialize(); while(1) { printf("-------- Stack Test --------\n"); printf("- 1. Push -\n"); printf("- 2. Pop -\n"); printf("- 3. Print Stack -\n"); printf("- 4. Exit -\n"); printf("----------------------------\n"); printf("- Stack Top : %d\n\n", nStackCounter + 1); printf("Select : "); scanf("%d", &nSelect); fflush(stdin); switch(nSelect) { case 1: printf("Push Number : "); scanf("%d", &nStackData); push(nStackData); fflush(stdin); break; case 2: pop(); break; case 3: PrintStack(); break; case 4: exit(1); break; default: break; } getch(); fflush(stdin); system("cls"); } } void StackInitialize() { nStackCounter = -1; } bool isEmpty() { return (nStackCounter < 0); } bool isFull() { return (nStackCounter >= (STACK_MAX - 1)); } void push(StackData sd) { if(isFull()) { printf("스택이 가득 찼습니다.\n"); return; } Stack[++nStackCounter] = sd; printf("Push %d\n\n", sd); } void pop() { if(isEmpty()) { printf("스택이 비어 있습니다.\n"); return; } printf("Pop %d\n\n", Stack[nStackCounter--]); } void PrintStack() { system("cls"); if(isEmpty()) { printf("스택이 비어 있습니다.\n"); return; } printf("-- Stack List --\n"); for(int i = nStackCounter; i > -1 ; --i) { printf("%d. %d\n", nStackCounter - i + 1, Stack[i]); } }