Stack

728x90
#include<stdio.h>
#define MAX_STACK_SIZE 100
 
int stack[MAX_STACK_SIZE];
int top=-1;
 
int IsEmpty(){
    if(top<0)
        return true;
    else
        return false;
    }
int IsFull(){
    if(top>=MAX_STACK_SIZE-1)
        return true;
    else
        return false;
}
 
void push(int value){
    if(IsFull()==true)
        printf("스택이 가득 찼습니다.");
    else
        stack[++top]=value; 
}
 
int pop(){
    if(IsEmpty()==true)
        printf("스택이 비었습니다.");
    else 
        return stack[top--];
}
 
int main(){
    
    push(3);
    push(5);
    push(12);
    printf("%d ",pop());
    printf("%d ",pop());
    printf("%d ",pop());
 
    return 0;
}

출처 : https://minimin2.tistory.com/3

 

[자료구조] C언어로 스택(Stack) 구현, 소스코드

안녕하세요 이번엔 C언어로 Stack을 구현해보겠습니다. 자료구조의 매우 기초적인 개념인 Stack이란 영어로 쌓아놓은 더미란 뜻입니다. LIFO(Last In First Out) 방식으로 가장 최근에 들어온 데이터가

minimin2.tistory.com

 

728x90