Skip to content

Commit

Permalink
Create main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
JawadSher authored Nov 13, 2024
1 parent 811fbea commit 9106263
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 19 - Heap Data Structure Problems/10 - BST to Max Heap/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution{
public:
void inOrder(Node* root, vector<int> &nodes){
if(root == NULL) return;

inOrder(root -> left, nodes);
nodes.push_back(root -> data);
inOrder(root -> right, nodes);
}

void inOrderToHeap(Node* root, vector<int> &nodes, int & index){
if(root == NULL) return;

inOrderToHeap(root -> left, nodes, index);
inOrderToHeap(root -> right, nodes, index);

root -> data = nodes[index++];
}

void convertToMaxHeapUtil(Node* root)
{
vector<int> nodes;
inOrder(root, nodes);

int index = 0;
inOrderToHeap(root, nodes, index);
}
};

0 comments on commit 9106263

Please sign in to comment.