@@ -28,10 +28,10 @@ static PyObject* BinaryTree___new__(PyTypeObject* type, PyObject *args, PyObject
28
28
BinaryTree *self;
29
29
self = reinterpret_cast <BinaryTree*>(type->tp_alloc (type, 0 ));
30
30
31
- // Check what this is: (python code below:)
32
- // obj = object.__new__(cls)
31
+ // // Check what this is: (python code below:)
32
+ // // obj = object.__new__(cls)
33
33
34
- // Assume that arguments are in the order below. Modify the python code such that this is true
34
+ // Assume that arguments are in the order below. Modify the python code such that this is true (ie; pass None for other arguments)
35
35
PyObject *key = PyObject_GetItem (args, PyZero);
36
36
PyObject *root_data = PyObject_GetItem (args, PyOne);
37
37
PyObject *comp = PyObject_GetItem (args, PyTwo);
@@ -42,20 +42,21 @@ static PyObject* BinaryTree___new__(PyTypeObject* type, PyObject *args, PyObject
42
42
}
43
43
Py_INCREF (Py_None);
44
44
key = root_data == Py_None ? Py_None : key; // This key is the argument, not self->key
45
- std::cout<<" h1" <<std::endl;
46
45
47
- TN* r = reinterpret_cast <TN*>(TN___new__ (&TNType, args, kwds)); // check if this is correct
48
- std::cout<<" yay! Error solved! :)" <<std::endl;
49
-
50
- TreeNode* root = reinterpret_cast <TreeNode*>(TreeNode___new__ (&TreeNodeType, args, kwds)); // check if this is correct
51
- std::cout<<" h2" <<std::endl;
46
+ if (PyType_Ready (&TreeNodeType) < 0 ) { // This has to be present to
47
+ return NULL ;
48
+ }
49
+ TreeNode* root = reinterpret_cast <TreeNode*>(TreeNode___new__ (&TreeNodeType, args, kwds));
52
50
root->is_root = true ;
53
-
54
51
self->root_idx = 0 ;
55
52
56
53
// obj.tree= ArrayForTrees(TreeNode, [root])
57
54
PyObject* listroot = Py_BuildValue (" [i]" , root);
58
- self->tree = PyObject_CallMethod (reinterpret_cast <PyObject*>(&ArrayForTreesType)," __new__" , " OO" , &TreeNodeType, listroot);
55
+ if (PyType_Ready (&ArrayForTreesType) < 0 ) { // This has to be present to
56
+ return NULL ;
57
+ }
58
+ // TO DO: Fix the following line!
59
+ // self->tree = PyObject_CallMethod(reinterpret_cast<PyObject*>(&ArrayForTreesType),"__new__", "OO", &TreeNodeType, listroot);
59
60
self->size = 1 ;
60
61
61
62
if (comp == Py_None){
0 commit comments