16,002,004 members
See more:
hi,
i want to count the left and right count of node of a binary tree.

db structure is...

id_no | parent_no | placement
1 0 0
2 1 L
3 1 R
4 2 L

now if i input 1 as the node

Left = 2 and right = 1 i have to get.

Posted

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

This isn't a particularly difficult problem: it shoudln't take you more than half an hour to an hour at most!

## Solution 2

To Mr. OriginalGriff

Thanks for your comment about my "HOME WORK". for your kind information its not my home work. and thanks to you for not solving my problem. I did it myself.

any way solved program for all others who need it.

```int Cr = 0;
private void pNode(string node)
{
string sql = "select * from biodata_master where parent_no='" + node + "'";

DataTable dt = new DataTable();
dt = obj.SelectData(sql);

if (dt.Rows.Count == 1)
{
Cr = Cr + 1;
}
else if (dt.Rows.Count > 0)
{
Cr = Cr + 2;
pNode(dt.Select("PLACEMENT='Left'")[0].ItemArray[0].ToString());
pNode(dt.Select("PLACEMENT='Right'")[0].ItemArray[0].ToString());
}
}```

and please its my humble request to the people like you(Extreme Professionals) please do not demoralize the novices like me by saying these kind of words. Please don't take my word badly.

Thanking you.

Member 12097141 31-Oct-15 13:15pm
Sir, in this line you have used obj
dt = obj.SelectData(sql);
Here, what is obj ? Is this an object ? If yes, then where is the class and what is class structure?
Currently I have the same problem of counting left and right children of a node in a binary tree. Please, tell me so that I can check this code in my project.

Thanks and Regards
This class contains nothing but the methods where we can get the data or insert data into database with database connection.

Like, dt = obj.SelectData(sql);

In SelectData I am passing the select query to fetch the whole data into a DataTable. Nothing else. You don't need to worry about this at all.