【问题标题】:Remove an item from a linked list [closed]从链接列表中删除项目[关闭]
【发布时间】:2013-03-29 21:13:05
【问题描述】:
struct node{
    int number;
    node *next;
    };
...
node* pOne;
node* pEnd;
// create node temp 
if( pOne==NULL)            // add temp in list
    pOne = temp;
    pEnd = temp;
else { 
    pEnd->next = temp;
    pEnd = temp;
} 

如果我想从列表中删除一个项目怎么办? 就是说相邻元素的变化指向下面的指针就很清楚了。 如何从内存中删除一个项目?

什么时候不链接它会收集垃圾收集器?

【问题讨论】:

  • C++ 没有垃圾收集器。你必须delete它。
  • 如果不新建怎么办?
  • 如果你没有用new创建那么你不要删除它。
  • 如果程序中没有垃圾,什么时候删除不需要的对象?

标签: c++ list struct heap-memory


【解决方案1】:

你必须自己从内存中释放它,看看这个其他的stackoverflow答案

Does delete [] deallocate memory allocated by pointers to pointers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 2014-12-21
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多