1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define Maxlen 100 //定义输入字符的长度 5 6 //顺序栈 7 typedef struct 8 { 9 char data[Maxlen];//存储字符 10 int top; 11 }SeqStack; 12 13 SeqStack* Init()//栈初始化 14 { 15 SeqStack *s; 16 s=(SeqStack *) malloc ( sizeof(SeqStack) ); 17 s->top = -1; 18 return s; 19 } 20 21 void Destroy(SeqStack *s)//释放存储空间 22 { 23 free(s); 24 } 25 26 int IsFull(SeqStack *s)//判断为满 27 { 28 return (s->top == Maxlen-1) ? 1:0; 29 } 30 31 int IsEmpty(SeqStack *s)//判断为空 32 { 33 return (s->top == -1) ? 1:0; 34 } 35 36 void Push(SeqStack *s, char e)//入栈 37 { 38 if( IsFull(s) ) 39 { 40 printf("栈为满,无法入栈! "); 41 return; 42 } 43 s->top ++; 44 s->data[ s->top ] = e; 45 } 46 47 int Pop(SeqStack *s)//出栈 48 { 49 char e; 50 if( IsEmpty(s) ) 51 { 52 printf("栈为空,没有数据! "); 53 return NULL; 54 } 55 e = s->data[ s->top ]; 56 s->top --; 57 return e; 58 } 59 60 61 //返回字符数组元素的个数 62 int Mystrlen(char *str) 63 { 64 int num = 0; 65 for(;*str!='