Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求教大牛,我的bst为什么new不到空间?

Posted by askaquest at 2011-03-09 13:05:50
我的bst如下,调试发现root总是NULL?为什么?

#include <iostream>
using namespace std;

struct Node
{
	Node *lc,*rc;
	int data;
};
Node * root=NULL;

void insert(Node * root,int num)
{
	if(root==NULL)
	{
		root=new Node;
		root->data=num;
		root->lc=NULL;
		root->rc=NULL;
		return ;
	}

	if(num>root->data)
		insert(root->rc,num);
	else
		insert(root->lc,num);
}

void output(Node * root)
{
	if(root==NULL)
		return;
	output(root->lc);
	output(root->rc);
	printf("%d ",root->data);
}

int main()
{
	int input;

	while(scanf("%d",&input),input!=0)
	{
		insert(root,input);
	}

	output(root);
	printf("\n");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator