新手求问一个双向链表的问题
双向链表析构的时候出错了, 找了半天没找出来, 代码如下:
class DLinkedLIST
{
struct NODE
{
char *Data;
struct NODE *pPre;
struct NODE *pNext;
NODE(const char *D) : pPre(), pNext()
{
if(D == NULL)
{
Data = new char[1];
*Data = '\0';
}
else
{
Data = new char[strlen(D) + 1];
strcpy(Data, D);
}
}
~NODE(void)
{
delete[] Data;
}
};
NODE *Head;
public:
DLinkedLIST(void):Head() {}
~DLinkedLIST(void) { Destroy(); }
bool Destroy(void)
{
NODE *Temp = Head;
printf("开始销毁链表...\n");
while(Head)
{
Head = Head->pNext;
delete Temp;
Temp = Head;
}
Temp = NULL;
delete Head;
Head = NULL;
printf("销毁成功!\n");
return true;
}