棧的定義及基本操作
阿新 • • 發佈:2018-12-11
#include "stdafx.h" #include<stdio.h> #include<stdlib.h> #include<cstring> #define max 50; typedef struct Tnode { char data; struct Tnode *lnode; struct Tnode *rnode; }Tnode; typedef Tnode* type; typedef struct { type data[50]; int top; }stack; void initialstack(stack *s) { s->top = 0; } int push(stack *s, type x) { if (s->top == 50) return -1; s->data[s->top++] = x; return 0; } type pop(stack *s) { if (s->top == 0) exit(-2); type x = s->data[--s->top]; return x; } bool isemty(stack *s) { if (s->top == 0) return true; else return false; } //3.36