新人,问个栈的小问题,答对送分

smartone1 smartone1 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位达人帮我看看这段代码有什么问题?
#include<stdio.h>
#include<stdlib.h>
void push(char x);
void pop();
void correct(enum Boolean{ }tag);
typedef struct Stack
{
char data;
struct Stack *next;
};
struct Stack *head,*p;
enum Boolean{FALSE,TRUE}tag;
void main()
{
head=(struct Stack*)malloc(sizeof(struct Stack));
head->data ='s';
head->next=NULL;

correct(tag);
if(tag)
printf("Right");
else
printf("Wrong");
}
void push(char x)
{
p=(struct Stack*)malloc(sizeof(struct Stack));
if(!p)
printf("There's no place.\n");
else
{
p->data=x;
p->next=head;
head=p;
}
}

void pop()
{
if(head->next==NULL)
printf("The stack is empty.\n");
else {

p=head;
head=head->next;
free(p);
}

}
void correct(enum Boolean{ }tag)
{
int i;
char y;

printf("Please enter a bds:");
for(i=0;y!='\n';i++)
{
scanf("%c",&y);

if((y==')'&&head->data=='(')||(y==']'&&head->data=='[')||(y=='}'&&head->data=='{'))

pop();
else if((y=='(')||(y=='{')||(y=='['))
push(y);

else

continue;
}
if(head->next==NULL)

tag=TRUE;
else
tag=FALSE;
}

我就感觉head=(struct Stack*)malloc(sizeof(struct Stack));
head->data ='s';
head->next=NULL;
有问题,但我不知道怎么改?谢谢各位了
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
smartone1
VC/MFC 16,551 成员 421,605 内容