제목 : 13.1.1. 스택(Stack)
    
    
        
            
                | 
                    글번호:
                 | 
                
                 | 
                
                    244
                 | 
            
            
                | 
                    작성자:
                 | 
                
                 | 
                
                    
                        레드플러스
                        
                        
                    
                 | 
            
            
                | 
                    작성일:
                 | 
                
                 | 
                
                    
                        2005/12/07 오전 11:45:41 
                    
                 | 
            
            
            
                | 
                    조회수:
                 | 
                
                 | 
                
                    
                        5090
                    
                 | 
            
            
        
     
 
    
	
	
    
	/*
    Stack : 스택에 데이터를 저장하는 Push 함수와 데이터를 추출하는 Pop 함수를 작성한다.
*/
#include <stdio.h>
#define MaxSize 100        /* 스택 크기 */
int stack[MaxSize];        /* 스택 */
int sp = 0;                /* 스택 포인터 */
int Push(int);
int Pop(int*);
//메인 함수
int main(void)
{
    int c, n;
    printf("]");
    while((c = getchar()) != EOF)
    {
        if(c == '\n') continue;
        if(c == 'i' || c == 'I')
        {
            printf("data--> ");
            scanf("%d", &n);
            if(Push(n) == -1)
            {
                printf("스택이 가득 찼습니다.\n");
            }
        }
        if(c == 'o' || c == 'O')
        {
            if(Pop(&n) == -1)
            {
                printf("스택이 비었습니다.\n");
            }
            else
            {
                printf("stack data--> %d\n", n);
            }
        }
        printf("]");
    }
    return 0;
}
//스택에 데이터를 저장하는 함수
int Push(int n)
{
    if(sp < MaxSize)
    {
        stack[sp] = n;
        sp++;
        return 0;
    }
    else
    {
        return -1;//스택이 가득 찼을 때
    }
}
//스택에서 데이터를 추출하는 함수
int Pop(int *n)
{
    if(sp > 0)
    {
        sp--;
        *n = stack[sp];
        return 0;
    }
    else
    {
        return -1;//스택이 비었을 때
    }
}