关于二叉树求后序遍历
Cproject.exe 中的 0x00411509 处未处理的异常: 0xC00000FD: Stack overflow报的错是栈溢出,实在不会调了,请高手们帮帮忙!!
程序代码:
#include <stdio.h>
#include <string.h>
#define N 20
/*
typedef struct tree
{
char data;
typedef struct tree *rlink,*llink;
}t_tree;
*/
void work(char* x, char* y);
char* copy(char* s, int n, int m);
int pos(char a, char* b);
char sx[N],sy[N];
void work(char* x, char* y)
{
int l,c;
if(x != "")
{
l = strlen(x);
c = pos(x[0], y); //根在中序序列中的位置
work(copy(x, 1, c-1),copy(y, 0, c-1)); //递归调用左子树
work(copy(x, c+1, l-c),copy(y, c+1, l-c));//递归调用右子树
printf("%c",x[0]); //后序输出根结点
}
}
int pos(char a, char* b)
{
int i,l;
l = strlen(b);
for(i = 0; i < l; i ++)
if(b[i] == a)
return i;
}
char* copy(char* s, int n, int m)
{
int i,j=0;
char str[N];
for(i = n; i <= m; i ++)
str[j++] = s[i];
return str;
}
int main()
{
char x[N]={"abcdefg"}; //前序
char y[N]={"cbdafeg"}; //中序
work(x,y);
return 0;
}
[[it] 本帖最后由 cblovehh 于 2008-10-23 17:46 编辑 [/it]]









