[SOLVED] A C# /C++ Procedure/Function to be converted to mathematical form

Hi,

//This is an urgent problem please care to read this... and help me..

//i have a simple tree , it has a root node followed by nodes below it.. the leafs have structs CLeaf and Nodes have struct CNode

//the nodes and leafs have structures as defined below...

//struct or class ddefinition..

CNode

{

int nNodeID;

int m_nWeight;

}

CLeaf

{

int m_nValue;

int m_nWeight;

int m_nLeafID;

}////

// problem is to calculate the numerical value of root node..

//this is done in the following code..

//the value of the node just above the leaf is calculated as

foreach(CLeaf Leaf in Leafs)

{

nVal+=Leaf.m_nWeight* Leaf .m_nValue; //nVal is the value of node right above these leaves..

}

//now once we have the value of this node , doing the same thing for all nodes at this level and adding their values would as a result give me the value of the node above these //nodes

Repeating the process would give the value of root node.. and problem solved,. i have wrote the code below,. which is explaining the same stuff i described.

//i want to write this algo or code in mathematical form, .. could any one help me write its mathematical form... ? would it be some functions? summations ? sets ? please help..

// main function

int main()

{

int RootNode=1; //root node id is 1,

int nValue=null;

GetNodeValue(RootNode,out nValue);

WriteOutPut("Value of Root node is :" nValue.ToString() );

}

//algo / function

//This function/procedure Fills the value of node with id nNodeID in nVal

public int GetNodeValue(int nNodeID,out int nVal)

{

nVal=0;

CNode[] Nodes=null;

if(GetNodesBelow(nNodeID,-1,out Nodes)==0) //returns the Nodes below the node with id =nNodeID

{

m_strError=this.GetLastError();

return 0;

}

if(Nodes.Length>0) //if we have nodes below nodes...

{

foreach(CNode Node in Nodes)

{

int nValue;

if(GetNodeValue(Node.m_nNodeID,out nValue)==0) //recursively call this function again..

{

m_strError=GetLastError();

return 0;

}

nVal+=Node.m_nWeight*nValue;

}

return 1;

}

else //else we have leafs below the node

{

CLeafsDB qdb=new CLeafsDB();

qdb.Connect(m_strConnectionString);

CLeaf[] Leafs=null;

if(qdb.GetLeafsBelow(nNodeID,out Leafs)==0) //gets the leafs under the node , returns 0 if no leafs

{

m_strError=qdb.GetLastError();

qdb.Disconnect();

return 0;

}

foreach(CLeaf Leaf in Leafs)

{

nVal+=Leaf.m_nWeight* Leaf .m_nValue;

}

qdb.Disconnect();

}

return 1;

}

Thank you so much in advance,..