Home > database >  How to write this
How to write this

Time:10-07

#include #include #include # define maxsize 100 typedef char datatype; Typedef struct {datatype data [maxsize]; int top; } seqstack; Void SetNull (seqstack * s) {//empty stack s - & gt; Top=1; } int the Empty seqstack * (s)//whether the stack is Empty {the if (s - & gt; Top>=0) return false. The else return true; } seqstack * Push seqstack * s, datatype (x)//into the stack {the if (s - & gt; Top==maxsize - 1) {printf (" overflow "); Return NULL; } else {s - & gt; Top++; S - & gt; Data [s - & gt; top]=x; } return s; } datatype Pop (seqstack * s)//{if pop-up function (Empty (s)) {printf (" underflow "); Return NULL; } else {s - & gt; Top -; The return (s - & gt; Data [s - & gt; top + 1)); }} datatype Top seqstack * (s)//{if take the stack elements (Empty (s)) {printf (" underflow "); Return NULL; } the else return (s - & gt; The data/s - & gt; top); } void Show (seqstack * s) {//display the stack elements int I; Printf (" % c & lt; - TOP \ n, s - & gt; "" The data/s - & gt; top); For (I=s - & gt; Top - 1; i>=0; I -) {printf (" % c \ n ", s - & gt; Data [I]); } printf (" \ n "); } bool String_SYM (char * string, int len, seqstack * s)//judge {string center symmetry bool Express (char * string, int len)//judge whether the bracket of the expression of legal {//complete legal} to judge whether the bracket of the expression in the void main ()//main function {char string [50]. Int len. Printf (" please enter a string (length less than 50) : "); The scanf (" % s ", string); Len=strlen (string); If (String_SYM (string, len) printf (" % s has center symmetric relationship \ n ", string); The else printf (" % s \ n there is no central symmetry relations ", string); Printf (" please enter an expression (length less than 50) : "); The scanf (" % s ", string); Len=strlen (string); If (Express (string, len) printf (" \ n formula '% s' legal \ n "in parentheses, string); Formula for the else printf (" \ n '% s' in the parentheses illegal \ n ", string); }
  • Related