相比较于单链表,一个节点里多了一个指针指向上一个节点。
#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct Node{
int data;
struct Node *next;
struct Node *before;
} Node;
Node *Creat_double_linklist(int n)
{
Node *head=(Node *)malloc(sizeof(Node));
Node *p=head->next;
Node *q;
head=p->before;
for(int i=n;i>0;i--){
p->next=(Node*)malloc(sizeof(Node));
q=p;
p=p->next;
p->before=q;
}
return head;
}
int main()
{
int n;
cin>>n;
Node *head=Creat_double_linklist(n);
return 0;
}
2275

被折叠的 条评论
为什么被折叠?



