#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
struct node
{
int num;
struct node *next,*prior;
};
struct node *createlink(int n)
{
int i;
struct node *head,*p,*q;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
q=head;
head=(struct node*)malloc(sizeof(struct node));
//head->next=head;
q=head;
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->num);
////p->next=q->next;
//q->next=p;
//q=p;
q->next=p;
p->prior=q;
q=p;
}
q->next=head;
head->prior=q;
free(p);
return head;
//q->next=head;
//return head;
}
int main()
{
struct node *head;
head=createlink(3);
return 0;
}
#include<cstdlib>
#include<iostream>
using namespace std;
struct node
{
int num;
struct node *next,*prior;
};
struct node *createlink(int n)
{
int i;
struct node *head,*p,*q;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
q=head;
head=(struct node*)malloc(sizeof(struct node));
//head->next=head;
q=head;
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->num);
////p->next=q->next;
//q->next=p;
//q=p;
q->next=p;
p->prior=q;
q=p;
}
q->next=head;
head->prior=q;
free(p);
return head;
//q->next=head;
//return head;
}
int main()
{
struct node *head;
head=createlink(3);
return 0;
}
本文介绍了一个使用C++实现双向链表的基本过程。通过定义结构体并利用指针操作完成链表节点的创建与链接,最终形成一个循环双向链表。
442

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



