金融扶贫政策建议:设已有一个单循环链表,结点有三个域,pre 、data、next ,请设计一个算法,大家帮帮忙啊

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 15:12:40
把此链表改为一个双向循环的链表。用C或C++编程实现哦

struct node{
int data;
node *pre,next;
}

假设单循环链表中,头结点指针为head,所有结点的next域已全部赋值。

void Change(node *head)
{
if(head == NULL)
{
return;
}
if(head->next == NULL)
{
head->pre = head;
head->next = head;
return;
}

node *p,*q;
p=head;
q=head->next;
while(q->next != NULL)
{
q->pre = p;
p = p->next;
q = q->next;
}
q->next = head;
head->pre = q;
}

设计什么算法啊?
楼下的已经回答了,不用我再废话了,呵呵!
楼主好好看看书,这些东西不是很难的