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

📄 stack2.c

📁 自己做的常用库和实现的数据结构。public domain.
💻 C
字号:
#include<stdio.h>#include<stdlib.h>typedef struct a {	int x;	struct a *next;} A;A *top;void push(int c);A *pop(A *p);int main(void){	int c;	while( (c = getchar()) != EOF ) {		if(c == '[' || c == ']' || c == '{' || c == '}' || c == '(' || c == ')')		push(c);	}	while(top != NULL)		top = pop(top);	puts("");	return EXIT_SUCCESS;}void push(int c){	A *p;	static int cnt=0;	if( (p = malloc(sizeof(A))) == NULL ) {		fprintf(stderr, "Fatal: mem alloc failed !");		exit(EXIT_FAILURE);	}	p->x = c;	if(cnt++ == 0)		p->next = NULL;	else p->next = top;	top = p;}A *pop(A *p){	A *t;	printf("%c", p->x);	t = p->next;	free(p);	return t;}

⌨️ 快捷键说明

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