# 二叉搜索树的遍历问题-问答-阿里云开发者社区-阿里云

## 二叉搜索树的遍历问题

2016-03-23 16:06:16 1555 1
``````#include<string>
using namespace std;
class node{
public:
string name;
string keyword;
node* left;
node* right;
node(string a = 0, string b = 0, node* c = 0, node* d = 0) :
name(a), keyword(b), left(c), right(d){}
};
void search(string name2, string keyword2, bool& nameb, bool& keywordb,node* root){
node* p = root;
nameb = keywordb = false;
while (p){
if (name2 < p->name)
p = p->left;
else if (name2>p->name)
p = p->right;
else {
nameb = true;
if (keyword2 == p->keyword){
keywordb = true;
return;
}
else{
keywordb = false;
return;
}
}
}
}
node a;
a.name = "f";
a.keyword = "f";
a.left = new node("c", "c");
a.left->left = new node("123", "123");
a.right = new node("one", "one");
a.right->right = new  node("wang", "@@110");
node* root = &a;
cout << "请输入要登录的用户名和密码" << endl;
string c, d;
cin >> c >> d;
bool nameb, keywordb;//判断用户名和密码正确与否
search(c, d, nameb, keywordb,root);
if (nameb&&keywordb)cout << "登录成功！" << endl;
else if (nameb == true && keywordb == false){
while (keywordb == false){
cout << "您输入的密码有误，请重新输入密码" << endl;
cin >> d;
search(c,d, nameb, keywordb,root);
if (keywordb == true){
cout << "登录成功!" << endl;
return;
}
}
}
else {
cout << "您输入的用户名不存在！请重新输入用户名和密码！" << endl;
}
delete a.left->left;
a.left->left = 0;
delete a.left;
a.left = 0;
delete a.right->right;
a.right->right = 0;
delete a.right;
a.right = 0;
}

int main(){
}``````

• a123456678
2019-07-17 19:11:25
``````void search(string name2, string keyword2, bool& nameb, bool& keywordb,node* root){
node* p = root;
nameb = keywordb = false;
while (p){
if (name2 < p->name)
p = p->left;
else if (name2>p->name)
p = p->right;
else {
nameb = true;
if (keyword2 == p->keyword){
keywordb = true;
return;
}
else{
keywordb = false;
return;
}
}
}
}
node a;
a.name = "f";
a.keyword = "f";
a.left = new node("c", "c");
a.left->left = new node("123", "123");
a.right = new node("one", "one");
a.right->right = new  node("wang", "@@110");
node* root = &a;
cout << "请输入要登录的用户名和密码" << endl;
string c, d;
cin >> c >> d;
bool nameb, keywordb;//判断用户名和密码正确与否
search(c, d, nameb, keywordb,root);
if (nameb&&keywordb)
{
cout << "登录成功！" << endl;
}
else if (nameb == true && keywordb == false){
while (keywordb == false){
cout << "您输入的密码有误，请重新输入密码" << endl;
cin >> d;
search(c,d, nameb, keywordb,root);
if (keywordb == true){
cout << "登录成功!" << endl;
return;
}
}
}
else {
cout << "您输入的用户名不存在！请重新输入用户名和密码！" << endl;
delete a.left->left;
a.left->left = 0;
delete a.left;
a.left = 0;
delete a.right->right;
a.right->right = 0;
delete a.right;
a.right = 0;
}
delete a.left->left;
a.left->left = 0;
delete a.left;
a.left = 0;
delete a.right->right;
a.right->right = 0;
delete a.right;
a.right = 0;
}

int main(){
return 0;
}

``````
1 0

1

2022-05-12 16:19:14 237浏览量 回答数 1

1

2020-04-29 09:15:46 309浏览量 回答数 1

1

2020-04-14 16:42:27 2526浏览量 回答数 1

1

2018-05-08 01:43:59 582浏览量 回答数 1

0

Swarm mode 集群的搜索集群

2017-10-30 14:02:42 1611浏览量 回答数 0

1

uwsgi运行程序不能使用https问题

2017-09-14 07:23:37 3316浏览量 回答数 1

0

2016-05-18 08:34:36 2145浏览量 回答数 0

1

js 遍历多叉树怎么遍历

2016-03-19 11:02:55 2887浏览量 回答数 1

2

alioss图片搜索引擎抓取正常吗？

2013-08-31 11:40:36 5814浏览量 回答数 2

6

2012-08-30 14:28:28 10815浏览量 回答数 6
+关注
0

14879