新人,问个栈的小问题,答对送分
各位达人帮我看看这段代码有什么问题?
#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;
有问题,但我不知道怎么改?谢谢各位了