Home > Back-end >  Ask some problems of data structure, a great god answers
Ask some problems of data structure, a great god answers

Time:10-20

#include//string function header file
#include//character function header file
#include//the malloc ()
#include//INT_MAX
#include//standard input and output the header file, including EOF (=^ Z or F6), such as NULL
#include//the atoi (), the exit ()
#include//eof ()
#include//mathematical function header files, including the floor (), the ceil (), abs ()
#include//ftime ()
#include//macros va_start, va_arg and va_end, used to access the variable length argument lists
//function results state code, in the textbook page 10
using namespace std;
# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR 0
# define OK 1
# define the ERROR 0
# define STACK_INIT_SIZE 100;
# define STACKINCERMENT 10;
Typedef int the Status;
Typedef int SElemType;
Typedef struct {
SElemType * base;
SElemType * top;
Int stacksize;
} Sqstack;
The Status InitStack (Sqstack & amp; S)//create an empty stack;
{
S.b ase=(SElemType *) malloc (100 * sizeof (SElemType));
if(! S.b ase) exit (ERROR);
S.t op=S.b ase;
S.s tacksize=STACK_INIT_SIZE;
Return OK;
}
The Status GetTop (Sqstack S, SElemType & amp; E)//if the stack is not empty, will return to the top;
{
If (S.b ase==S.t op) return the ERROR;
E=* (S.t op - 1);
Return OK;
}
The Status of Push (Sqstack & amp; S, SElemType e)
{
If (S.t op - S.b ase>=S.s tacksize) {
S.b ase=(SElemType *) realloc (S.b ase, (S.s tacksize + 100) * sizeof (SElemType));
}
if(! S.b ase) exit (OVERFLOW);
S.t op=S.b ase + S.s tacksize;
S.s tacksize +=STACKINCERMENT;
}

The Status of Pop (Sqstack & amp; S, SElemType & amp; E)
{
If (S.t op==S.t op) return the ERROR;
E=* (-- S.t op);
Return OK;
}
The Status matching (string & amp; Exp)
{int I=0;
Int state=1;
SElemType e, S,
While (i<=sizeof (exp) & amp; & State) {
The switch exp [I] {
Case "(" : {Push (S, exp [I]); i++; break; }
Case ") ": {
if(! StackEmpty (S) & amp; & GetTop (S)=='(')
{Pop (S, e); i++; }
The else state=0;
break; }
}

Void main ()
{Sqstack S;
InitStack (S);
The Status matching (' (');

}
Don't know how to solve all the problems is to solve the () [] symbol matching problem

CodePudding user response:

Didn't say what problem
  • Related