0

Can someone convert this code to python??

//Code in C++: - #include<bits/stdc++.h> using namespace std; // BST node structure class Node { public: int val; int count; Node * left; Node * right; // Constructor Node(int num1, int num2) { this -> val = num1; this -> count = num2; this -> left = this -> right = NULL; } }; int addNode(Node * & root, int value, int countSmaller) { // Base case if (root == NULL) { root = new Node(value, 0); return countSmaller; } if (root -> val < value) { return root -> count + addNode(root -> right, value, countSmaller + 1); } else { root -> count++; return addNode(root -> left, value, countSmaller); } } int simpleMethod(int a[], int n) { int cnt = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[j] < a[i]) cnt++; } } return cnt; // Time complexity will be O(n^2);

6th Jun 2021, 8:03 PM
Tony Chahine`
3 odpowiedzi
0
The solution won't be that difficult as there are Python commands that are similar enough to the C commands. You just need to do the work. Do the code and show us where you are having problems. THAT we can help you with.
6th Jun 2021, 9:00 PM
Jerry Hobby
Jerry Hobby - avatar
+ 2
There is a Binary Tree lesson here; https://www.sololearn.com/learn/322/?ref=app See the implementations at the bottom for one in python. You may be able to work it out from there.
6th Jun 2021, 8:20 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
No , we don't work for you .Go to a freelance website for such stuff . Use Q&A for genuine query related to programming .
6th Jun 2021, 8:06 PM
Abhay
Abhay - avatar