We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 811fbea commit 9106263Copy full SHA for 9106263
19 - Heap Data Structure Problems/10 - BST to Max Heap/main.cpp
@@ -0,0 +1,28 @@
1
+class Solution{
2
+ public:
3
+ void inOrder(Node* root, vector<int> &nodes){
4
+ if(root == NULL) return;
5
+
6
+ inOrder(root -> left, nodes);
7
+ nodes.push_back(root -> data);
8
+ inOrder(root -> right, nodes);
9
+ }
10
11
+ void inOrderToHeap(Node* root, vector<int> &nodes, int & index){
12
13
14
+ inOrderToHeap(root -> left, nodes, index);
15
+ inOrderToHeap(root -> right, nodes, index);
16
17
+ root -> data = nodes[index++];
18
19
20
+ void convertToMaxHeapUtil(Node* root)
21
+ {
22
+ vector<int> nodes;
23
+ inOrder(root, nodes);
24
25
+ int index = 0;
26
+ inOrderToHeap(root, nodes, index);
27
28
+};
0 commit comments