@@ -88,7 +88,7 @@ static PyObject* SelfBalancingBinaryTree__right_rotate(SelfBalancingBinaryTree*
88
88
PyObject* k = PyObject_GetItem (args, PyOne);
89
89
BinaryTree* bt = self->bst ->binary_tree ;
90
90
PyObject* y = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->right ;
91
- if (y!= Py_None) {
91
+ if (y != Py_None) {
92
92
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (y)])->parent = j;
93
93
}
94
94
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (j)])->left = y;
@@ -110,6 +110,33 @@ static PyObject* SelfBalancingBinaryTree__right_rotate(SelfBalancingBinaryTree*
110
110
Py_RETURN_NONE;
111
111
}
112
112
113
+ static PyObject* SelfBalancingBinaryTree__left_rotate (SelfBalancingBinaryTree* self, PyObject *args) {
114
+ PyObject* j = PyObject_GetItem (args, PyZero);
115
+ PyObject* k = PyObject_GetItem (args, PyOne);
116
+ BinaryTree* bt = self->bst ->binary_tree ;
117
+ PyObject* y = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->left ;
118
+ if (y != Py_None) {
119
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (y)])->parent = j;
120
+ }
121
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (j)])->right = y;
122
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (j)])->parent ;
123
+ if (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent != Py_None) {
124
+ if (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent )])->left == j) {
125
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent )])->left = k;
126
+ }
127
+ else {
128
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent )])->right = k;
129
+ }
130
+ }
131
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (j)])->parent = k;
132
+ reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->left = j;
133
+ PyObject* kp = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (k)])->parent ;
134
+ if (kp == Py_None) {
135
+ bt->root_idx = k;
136
+ }
137
+ Py_RETURN_NONE;
138
+ }
139
+
113
140
static struct PyMethodDef SelfBalancingBinaryTree_PyMethodDef[] = {
114
141
{" insert" , (PyCFunction) SelfBalancingBinaryTree_insert, METH_VARARGS | METH_KEYWORDS, NULL },
115
142
{" delete" , (PyCFunction) SelfBalancingBinaryTree_delete, METH_VARARGS | METH_KEYWORDS, NULL },
@@ -123,6 +150,7 @@ static struct PyMethodDef SelfBalancingBinaryTree_PyMethodDef[] = {
123
150
{" rank" , (PyCFunction) SelfBalancingBinaryTree_rank, METH_VARARGS, NULL },
124
151
{" select" , (PyCFunction) SelfBalancingBinaryTree_select, METH_VARARGS, NULL },
125
152
{" _right_rotate" , (PyCFunction) SelfBalancingBinaryTree__right_rotate, METH_VARARGS, NULL },
153
+ {" _left_rotate" , (PyCFunction) SelfBalancingBinaryTree__left_rotate, METH_VARARGS, NULL },
126
154
{NULL }
127
155
};
128
156
0 commit comments