Skip to content

Commit

Permalink
Merge pull request #3 from LiuXingLong/tyler.liu-feature
Browse files Browse the repository at this point in the history
Tyler.liu feature
  • Loading branch information
LiuXingLong authored Dec 6, 2018
2 parents e409775 + 66a74d0 commit 1951b57
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions BST/bst/bst.depend
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# depslib dependency file v1.0
1544098639 source:c:\users\hnust_liuxinglong\desktop\tree\bst\bst\main.cpp
1544106431 source:c:\users\hnust_liuxinglong\desktop\tree\bst\bst\main.cpp
<time.h>
<stdio.h>
<fstream>
<iostream>
"bst.h"

1544077413 c:\users\hnust_liuxinglong\desktop\tree\bst\bst\include\bst.h
1544100096 c:\users\hnust_liuxinglong\desktop\tree\bst\bst\include\bst.h
<stdlib.h>
<string>
<iostream>

1544098605 source:c:\users\hnust_liuxinglong\desktop\tree\bst\bst\src\bst.cpp
1544112403 source:c:\users\hnust_liuxinglong\desktop\tree\bst\bst\src\bst.cpp
"bst.h"

18 changes: 11 additions & 7 deletions BST/bst/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ int main()
filename = "data\\set_" + std::to_string(i) + ".in";
cout << filename << endl;
infile.open(filename.c_str(),ios::in);
while( !infile.eof() ){
infile >> key;
infile >> value;
BstMap.bst_set(key,value,BstMap.BKDRHash(key),bst_p,parent);
if(infile){
while( !infile.eof() ){
infile >> key;
infile >> value;
BstMap.bst_set(key,value,BstMap.BKDRHash(key),bst_p,parent);
}
infile.close();
e_time = clock();
cout<< "Data loading Time:" << (double)(e_time-s_time)/CLOCKS_PER_SEC << "s" << endl;
}else{
cout<< "Open Data: " + filename + " Error" << endl;
}
infile.close();
e_time = clock();
cout<< "Data loading Time:" << (double)(e_time-s_time)/CLOCKS_PER_SEC << "s" << endl;
}
/// 加载更新数据
infile.open("data\\update.in",ios::in);
Expand Down
23 changes: 18 additions & 5 deletions BST/bst/src/bst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,37 @@ bool bst::bst_del(string key, unsigned int hash_key, BstNode *&bst_p)
BstNode *bst_h;
bst_h = bst_p;
bst_p = this->get_min_node(bst_p->rchild);
/// 处理删除节点,右子树中最小节点的孩子
if(bst_p->rchild != nullptr){
bst_p->parent->lchild = bst_p->rchild;
if(bst_p->parent->hash_key > bst_p->hash_key){
bst_p->parent->lchild = bst_p->rchild;
}else if(bst_p->parent->hash_key < bst_p->hash_key){
bst_p->parent->rchild = bst_p->rchild;
}
bst_p->rchild->parent = bst_p->parent;
}else{
bst_p->parent->lchild = nullptr;
if(bst_p->parent->hash_key > bst_p->hash_key){
bst_p->parent->lchild = nullptr;
}else if(bst_p->parent->hash_key < bst_p->hash_key){
bst_p->parent->rchild = nullptr;
}
}
/// 处理删除节点,左右孩子
bst_p->lchild = bst_h->lchild;
bst_h->lchild->parent = bst_p;
bst_p->rchild = bst_h->rchild;
bst_h->rchild->parent = bst_p;
if(bst_h->rchild != nullptr){
bst_h->rchild->parent = bst_p;
}
/// 处理删除节点,父亲节点
if(bst_h->parent == nullptr){
bst_p->parent = nullptr;
}else if(bst_h->parent->hash_key > bst_h->hash_key){
bst_h->parent->lchild = bst_p;
bst_p->parent = bst_h->parent->lchild;
bst_p->parent = bst_h->parent;
}else if(bst_h->parent->hash_key < bst_h->hash_key){
bst_h->parent->rchild = bst_p;
bst_p->parent = bst_h->parent->rchild;
bst_p->parent = bst_h->parent;
}
delete bst_h;
bst_h = nullptr;
Expand Down

0 comments on commit 1951b57

Please sign in to comment.