我不明白为什么会发生这样的错误:
while (currentNode != nullptr)
currentNode = currentNode->parent;
Run Code Online (Sandbox Code Playgroud)
我的while循环的条件应该阻止它....
例如,有一个练习说:
编写一个函数来从链表中删除一个节点,只给出该指针
这是解决方案:
void deleteNode(Node* toDelete) {
// this function essensially first copies the data from the next pointer
// and then, deletes the next pointer
// However, it doesn't work if trying to delete the last element in the list
Node *temp = toDelete->next; // create a temp, assign to the one after toDelete
toDelete->data = temp->data; // change toDelete's data to the one's after it
toDelete->next = temp->next; // change toDelete's next to the one's after it
delete …Run Code Online (Sandbox Code Playgroud) 例如,我想捕获异常类的异常层次结构的多个类的异常,我是否需要担心它们的顺序是什么?
我听说订单不重要因为异常处理内置于C++中,但我并不是百分之百确定.
我对吗?
我很困惑为什么有些人在删除它之后将指针(在前面的堆上创建)指向0 .
例如:
Node* newNode = new Node();
delete newNode;
newNode = 0; // why?
Run Code Online (Sandbox Code Playgroud)
如果删除的指针指向0或其他内容,为什么重要?