Pages

Friday, September 30, 2011

trees and data structure : skipping double pointer

many times it is felt to pass head pointers as parameter to functions...

v  simple solution is to pass by reference..
this way u dnt have to change internal syntaxes in side your insert functions and all other functions where modification in the data structure is required.


void insert ( struct T * & node, int data)
{
if (!node)
{ node = (struct T * )malloc(sizeof(struct T));
node->data = data;
node->left = node->right = NULL;
}
}

No comments:

Post a Comment