LeeBlog

导航

二叉树

第一次有点理解,写了个二叉树

#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
	char ch;
	struct Node *lc,*rc;
}node,*Link;
void Create( Link *L )
{
	char ch;
	while( scanf( "%c",&ch ),ch == ' ' || ch == '\n' );
	if( ch == '#' )
		*L = NULL;
	else
	{
		( *L ) = new node;
		( *L ) -> ch = ch;
		Create( &( *L ) -> lc );
		Create( &( *L ) -> rc );
	}
}
void Print( Link L )
{
	if( L )
	{
		Print( L -> lc );
		printf( "%c ",L -> ch );
		Print( L -> rc );
	}
}
int main(  )
{
	Link L;
	Create( &L );
	Print( L );
	system( "pause" );
	return 0;
}
//+-+*3##*x##x##x##/1##x##5##

posted on 2011-06-10 18:31  LeeBlog  阅读(252)  评论(0编辑  收藏  举报