⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.h

📁 这是一个语法分析器 这是一个语法分析器
💻 H
字号:
#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED

int new_stack(pstack *head, int size)
{
    (*head) = (pstack)malloc(sizeof(stack));
    if ((*head) == NULL)
        return -1;
    (*head)->buf = (int *)malloc(sizeof(int)*size);
    if ((*head)->buf == NULL)
        return -1;
    (*head)->buf_size = size;
    (*head)->ptr = 0;
    return 0;
}

int push(pstack head, int element)
{
    if (head->ptr == head->buf_size - 1)
        return -1;
    head->ptr++;
    head->buf[head->ptr] = element;
    return 0;
}

int top(pstack head)
{
    return head->buf[head->ptr];
}

int empty(pstack head)
{
    if (head->ptr == 0)
        return 1;
    return 0;
}

int pop(pstack head)
{
    if (empty(head))
        return -1;
    head->ptr--;
    return 0;
}

void delete_stack(pstack *head)
{
    free((*head)->buf);
    free((*head));
}
#endif // STACK_H_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -