i have started my midterm exersize than is on binary treescan anyone help me on the basics
i have started and i have made the following
on my tree.h file:
[CODE=cpp]struct treenode
{
int data;
struct treenode *left;
struct treenode *right;
};typedef struct treenode *PTR;
class tree
{
private:
PTR tree;
public:
void insert_node(PTR *pt,int x);
void preorder_traver sal(PTR t);
void inorder_travers al(PTR t);
void postorder_trave rsal(PTR t);
void find_node(PTR t,int x,int i);
};
[/CODE]
on my tree.cpp file:
[CODE=cpp]#include<stdio. h>
#include<conio. h>
#include<stdlib .h>
#include<string .h>
#include"tree.h "
void tree::insert_no de(PTR *pt,int x)
{
PTR t;
t=*pt;
if (t==NULL)
{
t=(PTR)malloc(s izeof(struct treenode));
t->data=x;
t->left=NULL;
t->right=NULL;
}
else
if (x<t->data)
insert_node(&(t->left),x);
else
insert_node(&(t->right),x);
*pt=t;
}
void tree::preorder_ traversal(PTR t)
{
if(t!=NULL)
{
printf("%d",t->data);
preorder_traver sal(t->left);
preorder_traver sal(t->right);
}
}
void tree::postorder _traversal(PTR t)
{
if (t!=NULL)
{
postorder_trave rsal(t->left);
postorder_trave rsal(t->right);
printf("%d",t->data);
}
}
void tree::inorder_t raversal(PTR t)
{
if (t!=NULL)
{
inorder_travers al(t->left);
printf("%d",t->data);
inorder_travers al(t->right);
}
}
void tree::find_node (PTR t,int x,int i)
{
i++;
if (t==NULL)
{
printf("not found");
printf("Made %d Try",i);
}
else if (t->data==x)
{
printf("Found") ;
printf("Made %d try",i);
}
else if (x<t->data)
find_node(t->left,x,i);
else
find_node(t->right,x,i);
}
[/CODE]
on a test.cpp file
[CODE=cpp]#include<stdio. h>
#include<conio. h>
#include<stdlib .h>
#include<string .h>
#include"tree.h "
main()
{
int x,n,i=0;
int choise;
PTR bt;
bt=NULL;
while(x!=0)
{
insert_node(&bt ,x);
printf("Give Number");
scanf("%d",&x);
}
printf("1.preor der\n");
printf("2.posto rder\n");
printf("3.inord er\n");
printf("4.findn ode\n");
printf("2.exit\ n");
printf("choise? ");
scanf("%d",&cho ise);
switch (choise)
{
case 1:
printf("preorde r\n");
preorder_traver sal(bt);
break;
case 2:
printf("postord er\n");
postorder_trave rsal(bt);
break;
case 3:
printf("inorder \n");
inorder_travers al(bt);
break;
case 4:
printf("GIve Number");
scanf("%d",&n);
find_node(bt,n, i);
break;
} while (choise!=5);
getch();
}[/CODE]
it gives me the error :
[BCC32 Error] test.cpp(16): E2268 Call to undefined function 'insert_node'
[BCC32 Error] test.cpp(33): E2268 Call to undefined function 'preorder_trave rsal'
[BCC32 Error] test.cpp(37): E2268 Call to undefined function 'postorder_trav ersal'
[BCC32 Error] test.cpp(41): E2268 Call to undefined function 'inorder_traver sal'
[BCC32 Error] test.cpp(46): E2268 Call to undefined function 'find_node'
[BCC32 Warning] test.cpp(49): W8019 Code has no effect
Do i forget something?????? ??
are there more()??
like void destroynode()?? ?
i have started and i have made the following
on my tree.h file:
[CODE=cpp]struct treenode
{
int data;
struct treenode *left;
struct treenode *right;
};typedef struct treenode *PTR;
class tree
{
private:
PTR tree;
public:
void insert_node(PTR *pt,int x);
void preorder_traver sal(PTR t);
void inorder_travers al(PTR t);
void postorder_trave rsal(PTR t);
void find_node(PTR t,int x,int i);
};
[/CODE]
on my tree.cpp file:
[CODE=cpp]#include<stdio. h>
#include<conio. h>
#include<stdlib .h>
#include<string .h>
#include"tree.h "
void tree::insert_no de(PTR *pt,int x)
{
PTR t;
t=*pt;
if (t==NULL)
{
t=(PTR)malloc(s izeof(struct treenode));
t->data=x;
t->left=NULL;
t->right=NULL;
}
else
if (x<t->data)
insert_node(&(t->left),x);
else
insert_node(&(t->right),x);
*pt=t;
}
void tree::preorder_ traversal(PTR t)
{
if(t!=NULL)
{
printf("%d",t->data);
preorder_traver sal(t->left);
preorder_traver sal(t->right);
}
}
void tree::postorder _traversal(PTR t)
{
if (t!=NULL)
{
postorder_trave rsal(t->left);
postorder_trave rsal(t->right);
printf("%d",t->data);
}
}
void tree::inorder_t raversal(PTR t)
{
if (t!=NULL)
{
inorder_travers al(t->left);
printf("%d",t->data);
inorder_travers al(t->right);
}
}
void tree::find_node (PTR t,int x,int i)
{
i++;
if (t==NULL)
{
printf("not found");
printf("Made %d Try",i);
}
else if (t->data==x)
{
printf("Found") ;
printf("Made %d try",i);
}
else if (x<t->data)
find_node(t->left,x,i);
else
find_node(t->right,x,i);
}
[/CODE]
on a test.cpp file
[CODE=cpp]#include<stdio. h>
#include<conio. h>
#include<stdlib .h>
#include<string .h>
#include"tree.h "
main()
{
int x,n,i=0;
int choise;
PTR bt;
bt=NULL;
while(x!=0)
{
insert_node(&bt ,x);
printf("Give Number");
scanf("%d",&x);
}
printf("1.preor der\n");
printf("2.posto rder\n");
printf("3.inord er\n");
printf("4.findn ode\n");
printf("2.exit\ n");
printf("choise? ");
scanf("%d",&cho ise);
switch (choise)
{
case 1:
printf("preorde r\n");
preorder_traver sal(bt);
break;
case 2:
printf("postord er\n");
postorder_trave rsal(bt);
break;
case 3:
printf("inorder \n");
inorder_travers al(bt);
break;
case 4:
printf("GIve Number");
scanf("%d",&n);
find_node(bt,n, i);
break;
} while (choise!=5);
getch();
}[/CODE]
it gives me the error :
[BCC32 Error] test.cpp(16): E2268 Call to undefined function 'insert_node'
[BCC32 Error] test.cpp(33): E2268 Call to undefined function 'preorder_trave rsal'
[BCC32 Error] test.cpp(37): E2268 Call to undefined function 'postorder_trav ersal'
[BCC32 Error] test.cpp(41): E2268 Call to undefined function 'inorder_traver sal'
[BCC32 Error] test.cpp(46): E2268 Call to undefined function 'find_node'
[BCC32 Warning] test.cpp(49): W8019 Code has no effect
Do i forget something?????? ??
are there more()??
like void destroynode()?? ?
Comment