inspiron630 0 Newbie Poster

I'm trying to remove memory leaks from my program, but I am new at this so I'm not sure how to do so on the follow code of mine.

I think that I need to free insertedNode but I'm not sure how:

BSTNode * BST::Insert(const std::string & v, BSTNode *&parentNode) {
	static BSTNode *insertedNode;

	if (parentNode == NULL) {
		parentNode = new BSTNode(v);
		insertedNode = *&parentNode;
		size++;
		return insertedNode;
	} else {
		if (parentNode->value.compare(v) > 0) {
			Insert(v, parentNode->left);
		} else if (parentNode->value.compare(v) < 0) {
			Insert(v, parentNode->right);
		} else if (parentNode->value.compare(v) == 0) {
			return NULL;
		}
	}
	return insertedNode;
}

and that function is called by my Insert(one parameter) public function:

BSTNode * BST::Insert(const std::string & v) {

	if (Find(v) != NULL) {
		return NULL;
	}
	return Insert(v, rootNode);
}

I made insertedNode static because that's the only way I found that it returned the correct node.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.