Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 775af6d

Browse files
program to check digits in 2 numbers
1 parent af1f6eb commit 775af6d

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

‎Data Structures/Trees/Binary Trees/BottomView.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ void BottomView(Node *root)
127127
}
128128

129129

130+
void UtilBottomView(Node *root,map<int,vector<int> >&m,int hd=0)
131+
{
132+
if(!root) return;
133+
134+
UtilBottomView(root->left,m,hd-1);
135+
136+
m[hd].push_back(root->data);
137+
138+
UtilBottomView(root->right,m,hd+1);
139+
140+
}
141+
void bottomView(Node *root)
142+
{
143+
144+
map<int,vector<int> >m;
145+
map<int,vector<int> >::iterator it;
146+
//populating the map
147+
UtilBottomView(root,m);
148+
149+
for(it = m.begin();it != m.end();it++)
150+
{
151+
152+
int j = it->second.size()-1;
153+
154+
cout<<it->second[j]<<" ";
155+
156+
}
157+
158+
}
159+
130160
int main()
131161
{
132162
Node *root = newNode(20);
@@ -138,5 +168,8 @@ int main()
138168
root->left->right->right = newNode(14);
139169
root->right->right = newNode(25);
140170

141-
BottomViewMap(root);
171+
BottomView(root);
172+
cout<<endl;
173+
174+
bottomView(root);
142175
}

‎General Programs/CheckDigits.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<iostream>
2+
3+
4+
using namespace std;
5+
6+
int fun(int n,int m)
7+
{
8+
int sum = n + m;
9+
int s = sum;
10+
int c1 = 0,c2=0;
11+
int nn = n;
12+
while(s>0)
13+
{
14+
c1++;
15+
s /= 10;
16+
17+
}
18+
19+
while(nn>0)
20+
{
21+
c2++;
22+
nn /= 10;
23+
}
24+
25+
if(c1==c2) return sum;
26+
27+
else return n ;
28+
}
29+
30+
int main()
31+
{
32+
cout<<fun(10,121);
33+
return 0;
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /