2018-08-19  本文已影响6人  tingshuo123

先进后出

#include <stdio.h>

#define STACK_SIZE 100
#define true 1
#define false 0
typedef int bool
int contents[STACK_SIZE];
int top = 0;

// 初始化栈
void make_empty()
{
    top = 0;
}

// 判断栈是否为空
bool is_empty()
{
    return top == 0;
}

// 判断栈是否以满
bool is_full()
{
    return top == STACK_SIZE;
}

// 入栈
bool push(int i)
{
    if (is_full()) {
        return false;
    }
    contents[top++] = i;
}

// 出栈
int pop()
{
    if (is_empty()) {
        return -1;
    }
    return contents[--top];
}
上一篇 下一篇

猜你喜欢

热点阅读