code error

Hello !
I have this four errors at this code, wich is supposed to be a binary tree when giving preorder and postorder traversals:

In function `main':
49: undefined reference to `postorder(node*)'
62: undefined reference to `postorder(node*)'
In function `Z8preorderP4node':
91: undefined reference to `postorder(node*)'
92: undefined reference to `postorder(node*)'
collect2: ld returned 1 exit status

and this warnings :
ArboreBinar.cpp: In function `int main()':
ArboreBinar.cpp:22: warning: unused variable 'p'
ArboreBinar.cpp:22: warning: unused variable 'q'
ArboreBinar.cpp: In function `void insert(node**, int)':
ArboreBinar.cpp:73: warning: statement has no effect
ArboreBinar.cpp:150:3: warning: no newline at end of file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  #include <stdio.h>
#include <conio.h>
#include <alloc.h>
#define MAX 101
#include <stdlib.h>

struct node 
{
	struct node *left ;
	int data ;
	struct node *right ;
} ;
		void insert(struct node **, int) ;
		void preorder(struct node *);
		void postorder(struct node *);
		void inorder(struct node *) ;
		struct node * recons(int *, int *, int) ;
		void deltree(struct node *) ;
		int in[MAX], pre[MAX], x ;
		int main( )
		{
			struct node *t, *p, *q ;
			int req, i, num ;
			t = NULL ; /* Empty tree */
		 
			printf("Introdu numarul de elemente ce urmeaza a fi inserate:") ;
			while(1)
			{
				scanf("%d" , &req) ;
				if (req >= MAX || req <= 0)
					printf ("nIntrodu numar cuprins intre 1 si 100.\n") ;
				else
						break ;
			}
			for(i = 0 ; i < req ; i++)
            {
				printf("Indrocuceti datele: ") ;
				scanf("%d" , &num) ;
				insert(&t , num) ;
			}
			printf("\nIn-order Traversal:\n") ;
			x = 0 ;
			inorder(t) ;
			printf("\nPre-order Traversal:\n") ;
			x = 0 ;
			preorder(t) ;
			printf("\nPost-order Traversa;:\n") ;
			x = 0 ;
			postorder (t) ;
			deltree(t) ; 
			t = NULL ;
			t = recons(in, pre, req) ;
			printf("\n\nAfter reconstruction of the binary tree.\n") ;
			x=0 ;
			printf("\nIn-order Traversal: \n") ;
			inorder(t) ;
			x = 0 ;
			printf("\nPre-order Traversal:\n") ; 
			preorder(t) ;
			x = 0 ;
			printf("\nPost-order Traversal:\n") ;
			postorder(t) ;
			deltree(t) ; 
			getch( ) ;
		}
		/*Inserts a new node in a binary search tree*/
		void insert(struct node **sr, int num)
		{
			if(*sr == NULL)
			{
				*sr = (struct node *) malloc(sizeof (struct node)) ;
				(*sr) -> left = NULL ;
				(*sr) -> data + num ;
				(*sr) ->right = NULL ;
				return ;
			}
			else /* Search the node to which new node will be attached */
			{
				/* If new data is less, traverse to left */
				if(num < (*sr) -> data)
					insert(&((*sr) -> left), num) ;
				else
					/*Else traverse to right*/
					insert(&((*sr) -> right), num) ;
			}
		}
		void preorder(struct node *t)
		{
			if(t != NULL)
			{
				postorder(t -> left) ;
				postorder(t -> right) ; 
				printf("%d\t", t -> data) ;
			}
		}
		void inorder(struct node *t)
		{
			if (t !=NULL)
			{
				inorder(t -> left) ;
				printf("%d\t", in[x++]=t -> data) ;
				inorder(t -> right) ;
			}
		}
		struct node * recons(int *inorder, int *preorder, int noofnodes )
		{
			struct node *temp, *left, *right ;
			int tempin[100], temppre[100], i, j ;
			if(noofnodes == 0)
				return NULL ;
			temp = (struct node *) malloc(sizeof(struct node)) ;
			temp -> data = preorder[0] ;
			temp -> left = NULL ;
			temp ->right = NULL ;
			if(noofnodes == 1)
				return temp ;
			for(i = 0 ; inorder[i] != preorder[0] ;)
				i++ ;
			if(i > 0)
			{ 
				for(j = 0 ; j <= i ; j++) 
					tempin[j] = inorder[j] ;
				for(j = 0 ; j<1 ; j++)
					temppre[j] = preorder[j+1] ;
			}
			left = recons(tempin, temppre, i) ;
			temp -> left = left ;
			if(i < noofnodes - 1)
			{
				for(j = i ; j< noofnodes - 1 ; j++)
				{
					tempin[j - i] = inorder[j+1] ;
					temppre[j - i] = preorder[j+ 1] ;
				}
			}
			right = recons(tempin, temppre, noofnodes - i - 1) ;
			temp -> right = right ;
			return temp ;
		}
		void deltree(struct node *t)
		{
			if(t != NULL)
			{
				deltree(t -> left) ;
				deltree(t -> right) ;
			}
			free(t) ;
		
		}
		
Last edited on
You have a function prototype for postorder(), but you never implemented it. The linker is complaining that you're trying to call it, but that it does not exist.
Can you tell me how to do it work ?
Write the postorder() function.

BTW, you need to pay attention to the warning on line 73. Did you mean = here rather than + ?
Yes, my mistake, now it runs but i still cand make it work how i want: to enter the preorder and inorder, and the program should give me the binary tree... Any ideas ?
Topic archived. No new replies allowed.