下面是排序树程序,我的意思是想改变CreateTree()函数,现在输入创建的值不是在main()中输入的吗?我不想在main()中输入ch值,而是在CreateTree()函数中输入,也就是将CreateTree()该成CreateTree(Tree *T)的形式.
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
    char data;
    struct node *lchild;
    struct node *rchild;
}*Tree, Tnode;
static void CreateTree(Tree *T, char ch);
static void VisitTree(Tree *T);
int main(void)
{
    Tree T = NULL;
    char ch;
    
    printf("Enter create tree string: \n");
    fflush(stdin);
    
    while (1)
    {
        scanf("%c", &ch);
        
        if (ch == '\n')
        {
            break;
        }
        
        CreateTree(&T, ch);  /* 创建二叉排序树 */
    }
    
    VisitTree(&T); /* 打印二叉排序树 */
    printf("\n");
    
    return 0;
}
static void CreateTree(Tree *T, char ch)
{
    if (*T == NULL) 
    {
        if (((*T) = (Tree)malloc(sizeof(Tnode))) == NULL)
        {
            exit(1);
        }                           
        (*T) -> data = ch;          
        (*T) -> lchild = NULL;     
      (*T) -> rchild = NULL;
    }
    else
    {
        if ((*T) -> data > ch)   
        {
            CreateTree(&(*T) -> lchild, ch);
        }
        else if ((*T) -> data < ch)  
        {
            CreateTree(&(*T) -> rchild, ch);
        }
    }
}
static void VisitTree(Tree *T)
{
    if (*T != NULL)
    {
        VisitTree(&(*T) -> lchild);
        printf("%c", (*T) -> data);
        VisitTree(&(*T) -> rchild);
    }
    free(*T);
}
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    

日出东方,唯我不败! 做任何东西都是耐得住寂寞,任何一个行业要有十年以上的积累才能成为专家



 
											






 
	    

 
	




 
										
					
	 以下是引用SunShining在2006-5-19 12:25:00的发言:
以下是引用SunShining在2006-5-19 12:25:00的发言: ,看着简单啊
,看着简单啊
 ~~怎么买金币..不懂.我以为积分就是金币..看来不是.
~~怎么买金币..不懂.我以为积分就是金币..看来不是.