struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
void createList(ListNode* &pHead){
pHead = new ListNode(-1);
int length = 5;
ListNode *p = pHead;
for (size_t i = 0; i < length; i++)
{
ListNode *node = new ListNode(i);
p->next = node;
p = node;
}
}
void destroyList(ListNode* pHead){
_ASSERT(pHead != NULL);
ListNode *pNext = pHead->next;
while (pNext!=NULL)
{
delete pHead;
pHead = pNext;
pNext = pHead->next;
};
delete pHead;
pHead = NULL;
}
C++建立及销毁链表
最新推荐文章于 2022-09-20 00:04:22 发布