怎样建立一个空的双向循环链表?麻烦把算法写下~感激不尽~

来源:百度知道 编辑:UC知道 时间:2024/04/28 14:00:46
原题是这样的:创建一个空的双向循环链表
status CreateList_Dul(DuLinkList &L);
完整的算法只怎样的呢?
我这是数据结构的题

Node *head;
Node *tail;
head->pre=tail;
head->next=tail;
tail->next=head;
tail->pre=head;

这个程序包括建立双向链表和增删改差的完整功能,你看看是不是你想要的?

#include "stdafx.h"
#include "iostream.h"
#include "malloc.h"

/*创建长度为n的双向循环链表,值为整数。
查找第k个元素并输出。
删除所有值为m的元素。
逆置链表并输出。
*/

int n;
typedef struct str
{
int num;
struct str *pre;
struct str *next;
}node;

void creat(node * h)
{
node *c,*r;
r=h;
cout<<"输入链表的长度: ";
cin>>n;
for(int i=0;i<n;i++)
{
c=(node *)malloc(sizeof(node));
cout<<"输入数值: "<<endl;
cin>>c->num;
r->next=c;
c->pre=r;
r=c;
}
r->next=h->next;
h->next->pre=r;
}//..................

void select(node *h,int k)
{
node *p;
p=h->next;
if(k>