Reputation: 9
I get an error like this
line 13 3 [Error] expected '=', ',', ';', 'asm' or 'attribute' before '.' token
Please help me solve this problem
#include<stdio.h>
#include<stdlib.h>
typedef struct T
{
int data;
struct T *r,*l;
}t;
struct stack
{
t* a[100];
int top;
}s1;
s1.top=-1;
void push(t* root)
{
s1.a[++s1.top]=root;
}
t* pop()
{
s1.a[s1.top--];
}
t* create(t *root,int ele)
{
//printf("\nits gion");
if(root==NULL)
{printf("\nits gion");
root=malloc(sizeof(t));
root->r=root->l=NULL;
root->data=ele;
}
//printf("\nits gion");
else if(ele<root->data)
{
root->l=create(root->l,ele);
}
else if(ele>root->data)
{
root->r=create(root->r,ele);
}
else
printf("\nduplicate ");
return root;
}
void
#include<stdio.h>
#include<stdlib.h>
typedef struct T
{
int data;
struct T *r,*l;
}t;
struct stack
{
t* a[100];
int top;
}s1;
s1.top=-1;
void push(t* root)
{
s1.a[++s1.top]=root;
}
t* pop()
{
s1.a[s1.top--];
}
t* create(t *root,int ele)
{
//printf("\nits gion");
if(root==NULL)
{printf("\nits gion");
root=malloc(sizeof(t));
root->r=root->l=NULL;
root->data=ele;
}
//printf("\nits gion");
else if(ele<root->data)
{
root->l=create(root->l,ele);
}
else if(ele>root->data)
{
root->r=create(root->r,ele);
}
else
printf("\nduplicate ");
return root;
}
void mo(t * root)
{
if(root->r==NULL)
printf("%d",root->data);
else
mo(root->r);
}
void inorder(t* root)
{ while(1)
{
while(root)
{
push(root);
root=root->l;
}
root=pop();
if(root==NULL) break;
printf("%d",root->data);
root=root->r;
}
}
void postorder(t* root)
{ if(root==NULL) return;
else
{
postorder(root->l);
postorder(root->r);
printf("%d",root->data);
}
}
void preorder(t* root)
{ if(root==NULL) return;
else
{
printf("%d",root->data);
preorder(root->l);
preorder(root->r);
}
}
void lo(t * root)
{
if(root->l==NULL)
printf("%d",root->data);
else
mo(root->l);
}
void search(t *root,int ele)
{ if(root==NULL)
printf("not fnd");
else if(ele==root->data) printf("\nele found");
else if(ele<root->data)
search(root->l,ele);
else if(ele>root->data)
search(root->r,ele);
}
void main()
{int ch,ele;
t *root=NULL;
do
{
printf("\n1.add 2.m 3.l 4.exit 5.search 6.preorder7.inorder 8.postorder");
scanf("%d",&ch);
if(ch==1) {scanf("%d",&ele);
//printf("\nits gion");
root=create(root,ele);}
if(ch==2)
mo(root);
if(ch==3)lo(root);
if(ch==5)
{
scanf("%d",&ele);
search(root,ele);
}
if(ch==6) preorder(root);
if(ch==7) inorder(root);
if(ch==8) postorder(root);
}while(ch!=4);
}
Upvotes: 0
Views: 35
Reputation: 2606
The compiler error on line 13 is for this code:
s1.top=-1;
which is not inside a function. C only compiles and executes code that's inside a function - starting by calling the main function.
Upvotes: 1