使用栈的括号匹配(c语言程序) 有什么错误?

来源:百度知道 编辑:UC知道 时间:2024/06/30 09:20:45
我编了几个小时的程序调剂老是有一个错误 各位大侠们可否帮我看下那里有错误
#include<stdio.h>
#include<stdlib.h>
#define MAX 100

typedef char Elem;

typedef struct
{ Elem a[MAX];
int top;
}Sqstack;
Sqstack s1;

void init(Sqstack *s);
Elem pop(Sqstack *s);
void push(Sqstack *s,Elem e);

void init(Sqstack *s)
{ s->top=-1;
}
void push(Sqstack *s ,Elem e)
{ if(s->top==MAX-1)
printf("stack full");
else
{s->top++; s->a[s->top]=e;}
}
Elem pop(Sqstack *s)
{ Elem x;
if(s->top==-1) { printf("stack underflow"); x=-1; }
else{ x=s->a[s->top]; s->top--; return x;}
}

main()
{ init(s);

char ch; Elem e,x; int top; Sqstack s1;
do
{
ch=getchar();
switch(ch)
{ case '(': push(s,c

#include<stdio.h>
#include<stdlib.h>
#include"iostream.h"
#define MAX 100

typedef char Elem;

typedef struct
{ Elem a[MAX];
int top;
}Sqstack;
Sqstack s1;

void init(Sqstack *s);
Elem pop(Sqstack *s);
void push(Sqstack *s,Elem e);

void init(Sqstack *s)
{
s->top=-1;
}
void push(Sqstack *s ,Elem e)
{
if(s->top==MAX-1)
printf("stack full");
else
{
s->top++;
s->a[s->top]=e;
}
}
Elem pop(Sqstack *s)
{
Elem x;
if(s->top==-1)
{
printf("stack underflow");// x=-1;
}
else
{
x=s->a[s->top];
s->top--;
return x;
}
}

main()
{
Sqstack s;
init(&s);
int j;
char ch;
Elem e,x;
// int top;
Sqstack s1;
printf(&quo