写了段代码,求改错!
#include <stdio.h>#include <stdlib.h>
#define ElemInput char
#define StackElementType char
#define Stack_Size 50
typedef struct SeqStack
{
StackElementType elem[Stack_Size];
int top;
}SeqStack;
typedef struct DqStack
{
StackElementType elem[Stack_Size];
int top[2];
}DqStack;
// int ENTER(); //提示输入,并选择出是否为‘标的物’
void InitStack(SeqStack *PointS);
void ChooseSign(ElemInput Elem,SeqStack *PointS);
void GetInput(StackElementType Elem,SeqStack *PointS);
void InitDqstack(DqStack *PointDs,SeqStack *Points);
void match(DqStack *Pointds);
void main()
{
DqStack *DoIt;
DoIt=(DqStack *)malloc(sizeof(DqStack));
SeqStack *ss;
ss=(SeqStack *)malloc(sizeof(SeqStack));
InitStack(ss);
ElemInput Ch;
printf("Input equation Please~!\n");
Ch=getchar();
while (Ch!='\n')
{
ChooseSign(Ch,ss);
Ch=getchar();
}
printf("Waiting......!\n");
InitDqstack(DoIt,ss);
match(DoIt);
}
void InitStack(SeqStack *Points)
{/*构造一个空栈 PointS*/
Points->top=-1;
}
void ChooseSign(StackElementType Elem,SeqStack *PointS)
{
switch(Elem) /输入‘(’
{
case'(':
case')':
case'[':
case']':
case'{':
case'}':
GetInput(Elem,PointS); / 调试到这里的时候Elem是‘(’
}
}
void GetInput(StackElementType Elem,SeqStack *PointS)
{
if ((PointS->top+1)<Stack_Size)
{
PointS->top++; /top++后为哦0
PointS->elem[PointS->top]=Elem; /可是不知道为什么 这里的Elem为‘(’,但是PointS->elem[PointS->top]却等于‘50?.’求解!
}
else printf("Error_Overflow!");
}
void InitDqstack(DqStack *PointDs,SeqStack *Points)
{
PointDs->top[0]=0;
PointDs->top[1]=Points->top;
}
void match(DqStack *Pointds)
{
int i;
if ((Pointds->top[1]-Pointds->top[0]+1)%2!=0)
{
printf("Error~!\n");
}
for (i=0;i<=(Pointds->top[1]-Pointds->top[0]+1)/2;i++)
{
if (Pointds->elem[Pointds->top[0]]==Pointds->elem[Pointds->top[1]])
{
printf("true~!\n");
Pointds->top[0]++;
Pointds->top[1]--;
}
}
}