新人,问个栈的小问题,答对送分
各位达人帮我看看这段代码有什么问题?
#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;
有问题,但我不知道怎么改?谢谢各位了
#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;
有问题,但我不知道怎么改?谢谢各位了
...全文
相关推荐
高中历史之教学教研历史一百问看看你能答对多少七素材
高中历史之教学教研历史一百问看看你能答对多少七素材
高中历史之教学教研历史一百问看看你能答对多少十素材
高中历史之教学教研历史一百问看看你能答对多少十素材
英语四级考试算分器,可根据答对数计算出各部分的分数以及总数数
可根据各类题型答对题的数量计算出英语四级各部分的成绩以及最终的总成绩,很好用哦由于文件为swf格式,压缩包中附赠送swf播放器,O(∩_∩)O哈哈~
BaiduZhidaoSpider:百度知道爬虫,爬取问答对
该项目是一个针对百度知道的爬虫系统,用于自动抓取问答对并存储到本地和数据库。系统支持分步骤执行网页下载、解析与数据入库,具备日志记录与配置管理功能。通过多阶段处理流程实现问句搜索页及对应详情页的采集与
一张台湾语文试卷,93%的大陆孩子答题得0分,你能答对几题?.docx
一张台湾语文试卷,93%的大陆孩子答题得0分,你能答对几题?.docx


