Код: Выделить всё
template class Node {
private:
Node* parent;
Node* left;
Node* right;
unsigned int key;
T value;
public:
/*constructors, accessors, mutators, rotating functions are here*/
Код: Выделить всё
//This currently is only for deleting leaf nodes
void remove(unsigned int key) {
//Find the node being deleted
Node* delnode = this->select(key);
if (!delnode) { return; };
//If the value is a leaf node
if (!delnode->getLeft() && !delnode->getRIght()) {
//Store the parent node
Node* parent = delnode->getParent();
//The node is both root and leaf
if (!parent) {
delete delnode;
return;
};
//If the node is not a root, clip the parent connection
if (delnode->getKey() < parent->getKey()) {
parent->setLeft(NULL);
delnode->setParent(NULL);
} else if (delnode->getKey() > parent->getKey()) {
parent->setRight(NULL);
delnode->setParent(NULL);
};
//Delete the node now
delete delnode;
return;
};
};
Код: Выделить всё
if (!parent) {
delete delnode;
return;
};
Я не могу найти ошибку в моем предыдущем коде, которая могла бы привести к тому, что использование «delete» привело бы к выдаче «double free();» ошибка, в чем может быть причина?
Подробнее здесь: https://stackoverflow.com/questions/781 ... sing-fault