用的CB 结果不对 代码哪里有问题呢
#include<stdio.h>
#include<stdlib.h>
int item;
struct node{
char bracket;
struct node* next;};
int judge(char c0,char c)
{
if(c==')'&&c0=='('||c=='}'&&c0=='{'||c==']'&&c0=='[')
return 1;
else return 0;
}
void in_struct (char b,struct node* head)
{ struct node*q=(struct node*)malloc(sizeof(struct node));
q->bracket=b;
q->next=head;
head=q;
}
void out_struct(struct node*head)
{
if(head==NULL)
printf("has been empty,right bracket left");
else{item=head->bracket;
struct node*t=head->next;
free(head);
head=t;
}
}
int main(){
struct node*head=(struct node*)malloc(sizeof(struct node));
char ch;
ch=getchar();
head->bracket=ch;
head->next=NULL;
ch=getchar();
while(ch!='#')
{
if("ch=='('||ch=='{'||ch=='['")
in_struct(ch,head);
else if("ch==')'||ch=='}'||ch==']'")
{
if(judge(head->bracket,ch)==1)
out_struct(head);
else {printf("unmatched");
exit(0);}
}
ch=getchar();
}
if(head->bracket=='('||'{'||'[')
printf("left bracket left");
else printf("succeed");
return 0;
}