2013-03-13 3 views
0

이진 검색 트리로 작업하고 있습니다. 여기 트리에서 항목을 삭제하는 함수를 작성하고 있습니다. 다음 코드에서 :복사 생성자

if(root = NULL)//if there is nothing in the tree 
{ 
    cout<<"the Tree is empty"<<endl;//ouput to the screen 
    return;//exit the function 
} 

bool isFound = false;//tells us if the item is found 
Node* tmp = new Node();//declare a temp pointer 
Node* tmp2 = new Node();;//declare a temp pointer 
tmp* = *root;//assign the pointer to something 

그것은 복사 생성자를 호출,하지만 난이 그것을 지금 난 그냥이 같은 값을 복사 해요 :에, 당신은 포인터를 할당하고

Node& Node::operator= (const Node& node) 
{ 
    data = node.data; 
    left = node.left; 
    right = node.right; 
    return *this; 
} 
+0

실제 질문은 무엇입니까? – Michael

답변

1

을 당신이

*tmp = *root; 

tmproot 유형 Node*의이다 필요한 객체를 할당; *tmp*rootNode입니다.

if(root == NULL) 

+0

그러면 복사 생성자를 작성해야합니까? – compprog254

+0

@ TravisLeonSorensen은 리소스를 관리하고 있습니까? 자원의 소유권이 정의되어 있습니까? (그것은 내가 그 정보만을 가지고 대답 할 수있는 질문이 아니다) –

+0

@ TravisLeonSorensen 더 읽기 - http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three –

0
if(root = NULL) 

변화는 또한 잘못된 :

tmp* = *root;//assign the pointer to something