括弧配对问题
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define MAXSIZE 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();
}
四则运算问题
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define MAXSIZE 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,a);
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();
}
以上两个程序均有三个错误!!!希望有心人可以帮我修改,然后发到我的油箱里,十分感谢!!!油箱:fuxun2008@nwsuaf.edu.cn
791152837@qq.com
求助!!!数据结构问题.大家帮帮忙哦!别看我是菜鸟。。。。。。
最新推荐文章于 2022-03-26 10:36:40 发布