|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小弟不解,此程序报错,求大神解析
# include <stdio.h>
# include <stdlib.h>
# include <malloc.h>
typedef struct Node
{
int data;
struct Node * Prior;
struct Node * Next;
}Node;
typedef struct Node * LinkList;
void CombineList(LinkList * L , LinkList * P);//双向循环链表的合并
int main(void)
{
LinkList L;
int len,pos,val;
bool b;
printf("请输入链表长度:");
scanf("%d",&len);
printf("链表正在构造中......\n");
CreateListHead(&L,len);
printf("链表构造完毕......\n");
ShowList(P);
LinkList P;
printf("请输入链表长度:");
scanf("%d",&len);
printf("链表正在构造中......\n");
CreateListHead(&P,len);
printf("链表构造完毕......\n");
ShowList(P);
printf("链表正在合并......\n");
CombineList(&L,&P);
printf("合并完毕......\n");
printf("输出表内所有元素:\n");
ShowList(L);
printf("输出完毕......\n");
return 0;
}
void CreateListHead(LinkList * L,int len)//构造链表
{
LinkList p,r;
* L=(LinkList)malloc(sizeof(Node));
if(L == NULL)
{
printf("构造失败,终止程序!");
exit(-1);
}
r = *L;
for(int i = 0; i < len; i ++)
{
p = (LinkList)malloc(sizeof(Node));
if(p == NULL)
{
printf("内存分配失败,终止程序!\n");
exit(-1);
}
printf("请输入第%d个元素:",i+1);
scanf("%d",&p->data);
p->Prior = r;
r->Next=p;
r = p;
}
r->Next = * L;
return;
}
void CombineList(LinkList * p , LinkList * l)//双向循环链表的合并
{
LinkList m,n,s,r;
r = (*p)->Prior;
s = (*l)->Prior;
m = *p;
n = *l;
m->Prior->Next = n;
n->Prior->Next = m;
m->Prior = s;
n->Prior = r;
/*
LinkList m,n,r,s;
m = (*l);
n= *p;
r = m->Prior;
s = n->Prior;
s->Next = l;
(*l)->Next = s;
*/
/*
n->Next->Prior=r;
r->Next=n->Next;
n->Prior->Next = m;
m->Prior =s;
*/
// free(n);
return;
}
|
|