问题描述
- 数据结构c++循环单链表问题,急!!
-
CirSinglyList& operator+=(CirSinglyList &list) //尾插入list,集合并
解决方案
CirSinglyList& operator+=(CirSinglyList &list)
{
CirSinglyList *p = this;
while(p->next != NULL)
p = p->next;
while(list->next != NULL)
{
p->next = new CirSinglyList();
p->next = list;
p = p->next;
}
p->next = NULL;
return this;
}
CirSinglyList & operator=(CirSinglyList &list)
{
/* 自己写 */
}
解决方案二:
修改一下
CirSinglyList& operator+=(CirSinglyList &list)
{
CirSinglyList *p = this;
while(p->next != NULL)
p = p->next;
while(list->next != NULL)
{
p->next = new CirSinglyList();
p->next = list;
p = p->next;
list = list->next;
}
p->next = NULL;
return this;
}
CirSinglyList& operator=(CirSinglyList &list)
{
/* 自己写 */
}
时间: 2024-10-24 10:00:06