hi,
i just want to count the levels of random binary tree.
i have used a queue to do a level-order traversal.
So the depth is equal to the height of the tree node
stored int the tail of the queue,
here's the algorithms i used to get the level of the tree
but the debugger shows that p doesn't get the address of qData,Code:int levelCtr, nodeCtr = 0; QueueNodePtr headPtr = NULL, tailPtr = NULL, indexPtr = NULL, lastPtr = NULL; TreeNodePtr p;/*more code*/ lastPtr = tailPtr; indexPtr = headPtr; p = &( lastPtr -> qData ); while ( lastPtr != headPtr ) { while ( ( indexPtr -> qData.leftPtr != &( lastPtr -> qData ) ) || ( indexPtr -> qData.rightPtr != &( lastPtr -> qData ) ) ) { indexPtr = indexPtr -> nextPtr; } lastPtr = indexPtr; indexPtr = headPtr; levelCtr++; }
but the address of lastPtr
any hints are welcome,
trk



LinkBack URL
About LinkBacks


