From bfa9c142185327a9b0cfac614cb7ec9072d123c4 Mon Sep 17 00:00:00 2001 From: suprabhat123 <54973383+suprabhat123@users.noreply.github.com> Date: Wed, 23 Oct 2019 10:52:48 +0530 Subject: [PATCH 1/2] tower of honaoi --- tower of honoi | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tower of honoi diff --git a/tower of honoi b/tower of honoi new file mode 100644 index 00000000..4a6682fc --- /dev/null +++ b/tower of honoi @@ -0,0 +1,29 @@ +#include +using namespace std; + +//tower of HANOI function implementation +void TOH(int n,char Sour, char Aux,char Des) +{ + if(n==1) + { + cout<<"Move Disk "<>n; + //calling the TOH + TOH(n,'A','B','C'); + + return 0; +} From 14d2fd8a3360ecbeb91da15a4b420402d5b3f4b3 Mon Sep 17 00:00:00 2001 From: suprabhat123 <54973383+suprabhat123@users.noreply.github.com> Date: Wed, 23 Oct 2019 14:44:15 +0530 Subject: [PATCH 2/2] leaf nodes sum in a binary tree --- leaf nodes sum in a binary tree | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 leaf nodes sum in a binary tree diff --git a/leaf nodes sum in a binary tree b/leaf nodes sum in a binary tree new file mode 100644 index 00000000..e6a2096b --- /dev/null +++ b/leaf nodes sum in a binary tree @@ -0,0 +1,37 @@ + +#include +using namespace std; +struct Node{ + int data; + Node *left, *right; +}; +Node *newNode(int data){ + Node *temp = new Node(); + temp->data = data; + temp->left = temp->right = NULL; + return temp; +} +void leafSum(Node *root, int *sum){ + if (!root) + return; + if (!root->left && !root->right) + *sum += root->data; + leafSum(root->left, sum); + leafSum(root->right, sum); +} + +int main(){ + + Node *root = newNode(1); + root->left = newNode(2); + root->left->left = newNode(4); + root->left->right = newNode(5); + root->right = newNode(3); + root->right->right = newNode(7); + root->right->left = newNode(6); + root->right->left->right = newNode(8); + int sum = 0; + leafSum(root, &sum); + cout << sum << endl; + return 0; +}