hi, i'm currently learning C on my own. i explicitly made a binary tree just to see if my postorder procedure works. i have no idea why but at the end of running the program, before it does the last procedure, this appears:
[IMG]http://i56.tinypic.com/2nb52xx.jpg[/IMG]
everything else works fine. i know it must be the postorder which has the problem but i have no idea why.
please help me.
below is my code:
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node {
struct node *LeftNode;
char data;
struct node *RightNode;
};
node *makeNode(char c);
void visit(struct node *N);
void postorder (struct node *N);
void main(){
struct node *A = makeNode('A');
struct node *L = makeNode('L');
struct node *G = makeNode('G');
struct node *O = makeNode('O');
struct node *R = makeNode('R');
struct node *I = makeNode('I');
struct node *T = makeNode('T');
struct node *H = makeNode('H');
struct node *M = makeNode('M');
struct node *S = makeNode('S');
A->LeftNode = L;
L->LeftNode = G;
G->LeftNode = O;
G->RightNode = R;
L->RightNode = I;
A->RightNode = T;
T->LeftNode = H;
H->RightNode = M;
T->RightNode = S;
printf("Left Node of %c: %c\n", A->data, A->LeftNode->data);
printf("Left Node of %c: %c\n", L->data, L->LeftNode->data);
printf("Left Node of %c: %c\n", G->data, G->LeftNode->data);
printf("Right Node of %c: %c\n", G->data, G->RightNode->data);
printf("Right Node of %c: %c\n", L->data, L->RightNode->data);
printf("Right Node of %c: %c\n", A->data, A->RightNode->data);
printf("Left Node of %c: %c\n", T->data, T->LeftNode->data);
printf("Right Node of %c: %c\n", H->data, H->RightNode->data);
printf("Right Node of %c: %c\n", T->data, T->RightNode->data);
visit(A);
visit(L);
postorder(A);
}
node *makeNode(char c){
node *bago;
bago = new node;
bago->data = c;
bago->LeftNode = NULL;
bago->RightNode = NULL;
printf("New Node: %c\n", bago->data);
return bago;
}
void visit(struct node *N){
printf("%c", N->data);
}
void postorder (struct node *N){
postorder(N->LeftNode);
postorder(N->RightNode);
visit(N);
}