Arc matching
# Include <stdio. h>
# Include <conio. h>
# Include <malloc. h>
# Define Max size 100
Typedef int elemtype;
Typedef struct {
Elemtype ELEM [maxsize];
Int top;
} Sqstack;
Sqstack * s;
Void initstack (sqstack * s)
{
S-> Top = 0;
}
Void push (sqstack * s, elemtype X ){
If (S-> top> maxsize)
Printf ("overflow/N ");
Else
{
S-> ELEM [S-> top] = X;
S-> top ++;
}
}
Elemtype POP (sqstack * s)
{Elemtype X;
If (S-> Top = 0)
{Printf ("underflow! ");
X =-1;
}
Else
{S-> top --;
X = s-> ELEM [S-> top];
}
Return X;
}
Int gettop (sqstack S, elemtype & X)
{
If (S. Top = 0)
{Printf ("underflow! ");
X =-1;
}
Else
X = * (S. Top-1 );
Return X;
}
Void kuohaopipei ()
{
Initstack (s );
Char ch;
Ch = getchar ();
While (Ch! = NULL)
{
Switch (CH)
{Case ')': printf ("input error! /N "); break;
Case ']': printf ("input error! /N "); break;
Case '('ush (S, CH); break;
Case '['ush (S, CH); break;
}
Printf ("% C", CH );
Ch = getchar ();
}
While (CH)
{
Char ch;
Elemtype X;
Switch (precede (gettop (s), ch ))
{
Case '<' ush (S, CH );
Ch = getchar ();
Break;
Case '=': Pop (S, X );
Ch = getchar ();
Break;
Case '>': printf ("input error! /N ");
Break;
}
Printf ("% C", CH );
}
}
Void main ()
{S = (sqstack *) malloc (sizeof (sqstack ));
Initstack (s );
Pop (s );
Kuohaopipei ();
Getch ();
}
Arithmetic problems
# Include <stdio. h>
# Include <conio. h>
# Include <malloc. h>
# Define Max size 100
Typedef int elemtype;
Typedef struct {
Elemtype ELEM [maxsize];
Int top;
} Sqstack;
Sqstack * s;
Void initstack (sqstack * s)
{
S-> Top = 0;
}
Void push (sqstack * s, elemtype X ){
If (S-> top> maxsize)
Printf ("overflow/N ");
Else
{
S-> ELEM [S-> top] = X;
S-> top ++;
}
}
Elemtype POP (sqstack * s)
{Elemtype X;
If (S-> Top = 0)
{Printf ("underflow! ");
X =-1;
}
Else
{S-> top --;
X = s-> ELEM [S-> top];
}
Return X;
}
Int gettop (sqstack S, elemtype & X)
{
If (S. Top = 0)
{Printf ("underflow! ");
X =-1;
}
Else
X = * (S. Top-1 );
Return X;
}
Char evaluateexpression ()
{
Elemtype A, B, C;
Initstack (s );
Push (S ,'#');
C = getchar ();
While (C! = '#' | Gettop (s )! = '#')
{
If (! In (c, OP ))
{
Push (S, C );
C = getchar ();
}
Else
{
Pop (S, B );
Pop (s, );
Push (S, operate (A, C, B ));
C = getchar ();
}
}
Return gettop (s );
}
Void main ()
{S = (sqstack *) malloc (sizeof (sqstack ));
Initstack (s );
Pop (s );
Evaluateexpreession (s );
Getch ();
}
The preceding two programs have three errors !!! I hope someone who cares can help me modify it and send it to my fuel tank. Thank you very much !!! Tank: fuxun2008@nwsuaf.edu.cn
791152837@qq.com