推荐星级:
  • 1
  • 2
  • 3
  • 4
  • 5

C语言中的栈应用:表达式求值与函数调用.docx

更新时间:2026-10-15 21:05:00 大小:38K 上传用户:烟雨查看TA发布的资源 标签:C语言栈表达式求值函数调用LIFO 下载积分:2分 评价赚积分 (如何评价?) 打赏 收藏 评论(0) 举报

资料介绍

C语言中的栈应用:表达式求值与函数调用

一、栈的基本操作

栈是后进先出(LIFO)的数据结构,所有操作都在栈顶进行。

typedef struct {
    int *data;
    int top;
    int capacity;
} Stack;

void init(Stack *s, int capacity) {
    s->data = (int *)malloc(capacity * sizeof(int));
    s->top = -1;
    s->capacity = capacity;
}

void push(Stack *s, int value) {
    if (s->top < s->capacity - 1) {
        s->data[++s->top] = value;
    }
}

int pop(Stack *s) {
    if (s->top >= 0) {
        return s->data[s->top--];
    }
    return -1;
}

int peek(Stack *s) {
    return s->data[s->top];
}

int isEmpty(Stack *s) {
    return s->top == -1;
}


部分文件列表

文件名 大小
C语言中的栈应用:表达式求值与函数调用.docx 38K

全部评论(0)

暂无评论

上传资源 上传优质资源有赏金

  • 打赏
  • 30日榜单

推荐下载