but the debugger shows that p doesn't get the address of qData,
but the address of lastPtr
This is normal. The address of the first element of a structure is generally the address of the structure.
Code:
#include <stdio.h>
int main (void)
{
struct
{ int x, y} myStruct;
printf ("myStruct: %p\n", &myStruct);
printf ("myStruct.x: %p\n", &myStruct.x);
printf ("myStruct.y: %p\n", &myStruct.y);
return 0;
}
And the output
Code:
myStruct: 8f120
myStruct.x: 8f120
myStruct.y: 8f124
Quzah's algorithm is the correct(TM) way to go about this kind of problem though; figure out the depth of the left subtree, the right subtree, pick the biggest, and add 1.