Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

need the code badly...
Posted

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!
 
Share this answer
 
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.
 
Share this answer
 
Comments
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
Pranjal Madheshiya
pranjalmadheshiya@gmail.com
Arkadeep De 1-Nov-15 11:30am    
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900