0% found this document useful (0 votes)
24 views

Lecture-075 3 Is Binary Tree Heap - CPP

Binary

Uploaded by

maragonirohansai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lecture-075 3 Is Binary Tree Heap - CPP

Binary

Uploaded by

maragonirohansai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1 #include<bits/stdc++.h>#include"Tree.

h"usingnamespaceintcountNodes(Node* root)if
NULLreturn0intcountNodesintcountNodesreturn1boolisCBT(Node* root, intintifNULL
returntrueifreturnfalseboolisCBT21boolisCBT22returnboolisMaxOrder(Node* root)if
NULLreturntrueifNULLNULLreturntrueifNULLreturnboolisMaxOrderboolisMaxOrderbool
returnboolisMinOrder(Node* root)ifNULLreturntrueifNULLNULLreturntrueifNULLreturn
boolisMinOrderboolisMinOrderboolreturnboolcheckMaxHeap(Node* root)returnisCBT0
countNodesisMaxOrderboolcheckMinHeap(Node* root)returnisCBT0countNodes
isMaxOrderintmain()NULLbuildTreeintcheckMaxHeapintcheckMinHeapif"Given Binary
Tree is a Max Heap!"elseif"Given Binary Tree is a Min Heap!"else"Given Binary Tree is
not a Heap!"return0/*
2 40 20 10 -1 -1 15 -1 -1 25 -1 -1
3 35 24 15 6 -1 -1 -1 11 -1 -1 29 -1 -1
4 12 44 -1 -1 -1
5 42 45 12 -1 -1 9 -1 -1 39 6 -1 -1 12 -1 -1
6 13 14 16 -1 -1 17 -1 -1 15 -1 19 -1 -1
7 20 25 27 -1 -1 29 -1 -1 -1
8 40 42 49 -1 -1 -1 47 -1 -1
9 34 77 140 -1 -1 90 -1 -1 97 100 -1 -1 120 -1 -1
10 92 -1 -1
11 42 40 35 -1 -1 -1 -1
12 */</span></span>
13 std;</span>{
14 (root == ) {
15 ;
16 }
17 left = (root->left);
18 right = (root->right);
19 left + right + ;
20 }
21 index, cnt)</span></span>{
22 (root == ) {
23 ;
24 }
25 (index > cnt) {
26 ;
27 }
28 left = (root->left, *index + , cnt);
29 right = (root->right, *index + , cnt);
30 left && right;
31 }</span>{
32 (root == ) {
33 ;
34 }
35 (root->left == && root->right == ) {
36 ;
37 }
38 (root->right == ) {
39 (root->data) > (root->left->data);
40 }
41 left = (root->left);
42 right = (root->right);
43 curr = (root->data > root->left->data) && (root->data > root->right->data);
44 left && right && curr;
45 }</span>{
46 (root == ) {
47 ;
48 }
49 (root->left == && root->right == ) {
50 ;
51 }
52 (root->right == ) {
53 (root->data) < (root->left->data);
54 }
55 left = (root->left);
56 right = (root->right);
57 curr = (root->data < root->left->data) && (root->data < root->right->data);
58 left && right && curr;
59 }</span>{
60 (root, , (root)) && (root);
61 }</span>{
62 (root, , (root)) && (root);
63 }</span>{
64 Node* root = ;
65 root = (root);
66 isMaxHeapOrder = (root);
67 isMinHeapOrder = (root);
68 (isMaxHeapOrder){
69 cout << << endl;
70 } (isMinHeapOrder) {
71 cout << << endl;
72 } {
73 cout << << endl;
74 }
75 ;
76 }

You might also like