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

📄 stack.c

📁 一套接口
💻 C
字号:
static char rcsid[] = "$Id: stack.c 6 2007-01-22 00:45:22Z drhanson $";#include <stddef.h>#include "assert.h"#include "mem.h"#include "stack.h"#define T Stack_Tstruct T {	int count;	struct elem {		void *x;		struct elem *link;	} *head;};T Stack_new(void) {	T stk;	NEW(stk);	stk->count = 0;	stk->head = NULL;	return stk;}int Stack_empty(T stk) {	assert(stk);	return stk->count == 0;}void Stack_push(T stk, void *x) {	struct elem *t;	assert(stk);	NEW(t);	t->x = x;	t->link = stk->head;	stk->head = t;	stk->count++;}void *Stack_pop(T stk) {	void *x;	struct elem *t;	assert(stk);	assert(stk->count > 0);	t = stk->head;	stk->head = t->link;	stk->count--;	x = t->x;	FREE(t);	return x;}void Stack_free(T *stk) {	struct elem *t, *u;	assert(stk && *stk);	for (t = (*stk)->head; t; t = u) {		u = t->link;		FREE(t);	}	FREE(*stk);}

⌨️ 快捷键说明

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