Help !!! Data structure problems. Please help me! Don't look at me as a cainiao ......

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.