stack.c

来自「Multi-module programs and MAKE」· C语言 代码 · 共 32 行

C
32
字号
#include <stdio.h>#include "stack.h"#define MAXVAL 100                 /* maximum depth of val stack *//* even better, we could make the following two defines "static"   and thus hide these data structures from the rest of the sources */int sp = 0;                        /* next free stack position */int val[MAXVAL];                   /* value stack *//* note: "f" is a funny name for a generic int--"i" would be better *//* push: push f onto value stack */void push(int f){    if (sp < MAXVAL)	val[sp++] = f;    else	printf("error: stack full, can't push %d\n", f);}/* pop: pop and return top value from stack */int pop(void){    if (sp > 0)	return val[--sp];    else{	printf("error: stack empty\n");	return 0;    }}

⌨️ 快捷键说明

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