(回溯算法)
1 typedef struct BiTNode 2 { 3 int data; 4 BiTNode * lchild; 5 BiTNode * rchild; 6 }BiTNode, * BiTree; 7 8 void Function( BiTree T, int sum ) 9 { 10 int path[ MAXSIZE ]; 11 FindPath( T, sum, path, 0 ); 12 } 13 14 void FindPath( BiTree P, int sum, int path[], int top ) 15 { 16 if( p ) 17 { 18 sum -= P->data; //sum按值传递 19 if( sum == 0 ) 20 { 21 path[ top++ ] = P->data; 22 print( path, top ); //打印path数组top前的元素。top也是按值传递 23 } 24 else if( sum > 0 ) 25 { 26 path[ top++ ] = p->data; 27 FindPath( P->lchild, sum, path, top ); 28 FindPath( P->rchild, sum, path, top ); 29 } 30 } 31 }