코드 :트리 탐색 - 분할 오류 오류
#include<stdio.h>
#include<malloc.h>
typedef struct tree
{
char data;
struct tree *left;
struct tree *right;
}*pos;
pos stack[30];
int top=-1;
pos newnode(char b)
{
pos temp;
temp=(struct tree*)malloc(sizeof(struct tree));
temp->data=b;
temp->left=NULL;
temp->right=NULL;
return(temp);
}
void push(pos temp)
{
stack[++top]=temp;
}
pos pop()
{
pos p;
p=stack[top--];
return(p);
}
void inorder(pos t)
{
if(t!=NULL)
{
inorder(t->left);
printf("%s",t->data);
inorder(t->right);
}
}
void preorder(pos t)
{
if(t!=NULL)
{
printf("%s",t->data);
preorder(t->left);
inorder(t->right);
}
}
void postorder(pos t)
{
if(t!=NULL)
{
postorder(t->left);
postorder(t->right);
printf("%s",t->data);
}
}
void main()
{
char *a;
pos temp,t;
int j,i;
puts("Enter the expression :");
scanf("%s",&a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='*' || a[i]=='/' || a[i]=='+' || a[i]=='-')
{
temp=newnode(a[i]);
temp->right=pop();
temp->left=pop();
push(temp);
}
else
{
temp=newnode(a[i]);
push(temp);
}
}
inorder(temp);
printf("\n");
preorder(temp);
printf("\n");
postorder(temp);
}
오류 : 분할 고장이 코드는 이진 트리 탐색 및 중위하는 접미사와 접두사의 변환의 건설을위한
. 나는 어디에서 잘못 될지는 모르지만 같은 잘못을 계속 말합니다. 아무도 도와 줄 수 있습니까?
디버거를 사용해 보셨습니까? – easuter
여기서 [dsa] 태그는 무엇을하고 있습니까? – alk