我正在尝试将新的根元素添加到我的链接列表中。我已经知道正确的答案,但我不明白为什么有一个指向当前根元素的双指针。正确的代码如下:
void elementAsRoot(Element **oldRoot, Element *newRoot){
newRoot -> next = *oldRoot;
*oldRoot = newRoot;
}
最佳答案
我非常确定您可以删除双指针,因为您最终会取消引用双指针。
void elementAsRoot(Element *oldRoot, Element *newRoot) {
newRoot->next = oldRoot;
oldRoot = newRoot;
}
关于c - 链表添加新的根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56656169/