diff options
author | Haidong Ji | 2019-06-12 20:22:10 -0500 |
---|---|---|
committer | Haidong Ji | 2019-06-12 20:22:10 -0500 |
commit | 56c652e96dcedf3acbe6f37d9540044b2681b2da (patch) | |
tree | 2046aec9e4bb887067ba66c3a1271bbbbf4c398c | |
parent | 36d6a0c2b7c63d52f50e1509deed1f96ff1435d0 (diff) |
Comparing this against my Java and Python code, one more change was
needed: key value type changed from int to long. In reality, I'm not
sure if int would have worked, but I decided to be better safe than
sorry.
-rw-r--r-- | Sources/DataStructure.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Sources/DataStructure.cpp b/Sources/DataStructure.cpp index ebb4c2e..e9332c4 100644 --- a/Sources/DataStructure.cpp +++ b/Sources/DataStructure.cpp @@ -13,7 +13,7 @@ using std::endl; class TreeOrders { public: int n; - vector<int> key; + vector<long> key; vector<int> left; vector<int> right; @@ -30,7 +30,7 @@ public: bool is_Bst() { if (key.size()==0) return true; std::stack<int> keyIndexStack; - vector<int> result; + vector<long> result; bool walkLeft = true; int currentIndex = 0; keyIndexStack.push(currentIndex); @@ -44,14 +44,14 @@ public: int i = keyIndexStack.top(); keyIndexStack.pop(); if (result.size() > 0) { - if (key[i] <= result[(result.size()-1)]) return false; + if (key[i] < result[(result.size()-1)]) return false; } result.push_back(key[i]); walkLeft = false; } } else { if (right[currentIndex] != -1) { - if (key[right[currentIndex]] <= key[currentIndex]) return false; + if (key[right[currentIndex]] < key[currentIndex]) return false; currentIndex = right[currentIndex]; keyIndexStack.push(currentIndex); walkLeft = true; |