?? unittree.cpp
字號:
#include "unitTree.h"
void unitTree::add(char course[7])
{
Node *tp=root;
Node *temp=new Node;
strcpy(temp->course,course);
temp->left=0;
temp->right=0;
if(root==0){
root=temp;
return;
}
while(1)
{
if(temp->course[0]>tp->course[0]){
if(tp->right!=0)
tp=tp->right;
else{
tp->right=temp;
break;
}
}
else{
if(tp->left!=0)
tp=tp->left;
else{
tp->left=temp;
break;
}
}
}
}
void unitTree::show(Node *tmp)
{
cout<<tmp->course<<" ";
if(tmp->left!=0)
show(tmp->left);
if(tmp->right != 0)
show(tmp->right);
return;
}
void unitTree::destroy(Node *tmp)
{
if(tmp->left!=0)
destroy(tmp->left);
if(tmp->right != 0)
destroy(tmp->right);
delete tmp;
}
void unitTree::display()
{
show(root);
}
unitTree::~unitTree()
{
if(root!=NULL)
destroy(root);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -