| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 618 人关注过本帖
标题:[求助]链表合并!找错误!
取消只看楼主 加入收藏
独角龙
Rank: 1
等 级:新手上路
帖 子:221
专家分:0
注 册:2006-5-5
收藏
 问题点数:0 回复次数:2 
[求助]链表合并!找错误!

#include <stdio.h>
#include <malloc.h>

typedef struct node
{
int data;
struct node *prior, *next;
}*dLinkList, dListNode;

void CreateList(dLinkList *headPtr, dLinkList *tailPtr);
void Conatecate(dLinkList *headPtr1, dLinkList *tailPtr1, dLinkList *headPtr2, dLinkList *tailPtr2);
void VisitList(dLinkList headPtr, dLinkList tailPtr);
void DestroyList(dLinkList *headPtr, dLinkList *tailPtr);

int main(void)
{
dLinkList newhead1 = NULL, newtail1 = NULL;
dLinkList newhead2 = NULL, newtail2 = NULL;

CreateList(&newhead1, &newtail1);
VisitList(newhead1, newtail1);

CreateList(&newhead2, &newtail2);
VisitList(newhead2, newtail2);

Conatecate(&newhead1, &newtail2, &newhead2, &newtail2);

VisitList(newhead1, newtail1);

DestroyList(&newhead1, &newtail2);

return 0;
}

void CreateList(dLinkList *headPtr, dLinkList *tailPtr)
{
int newdata;
dLinkList newPtr = NULL;

printf("Enter one number:\n");
scanf("%d", &newdata);

while (newdata != 0)
{
newPtr = (dLinkList)malloc(sizeof(dListNode));
if (newPtr == NULL)
{
exit(1);
}

newPtr -> data = newdata;
newPtr -> next = NULL;

if (*headPtr == NULL)
{
newPtr -> next = *headPtr;
newPtr -> prior = *headPtr;
*headPtr = newPtr;
}
else
{
(*tailPtr) -> next = newPtr;
newPtr -> prior = *tailPtr;
}
newPtr -> next = NULL;
*tailPtr = newPtr;

printf("Enter one number:\n");
scanf("%d", &newdata);
}
}

void Conatecate(dLinkList *headPtr1, dLinkList *tailPtr1, dLinkList *headPtr2, dLinkList *tailPtr2)
{
(*tailPtr1) -> next = *headPtr2;
(*headPtr2) -> prior = *tailPtr1;
}

void VisitList(dLinkList headPtr, dLinkList tailPtr)
{
while(headPtr != NULL)
{
printf("%d ", headPtr -> data);
headPtr = headPtr -> next;
}
printf("\n");
}

void DestroyList(dLinkList *headPtr, dLinkList *tailPtr)
{
dLinkList temp;
while (*headPtr != NULL)
{
temp = *headPtr;
*headPtr = (*headPtr) -> next;
free(temp);
}
*headPtr = NULL;
*tailPtr = NULL;
}

搜索更多相关主题的帖子: 链表 
2006-05-27 11:47
独角龙
Rank: 1
等 级:新手上路
帖 子:221
专家分:0
注 册:2006-5-5
收藏
得分:0 


奋斗改变一切!!
2006-05-27 12:01
独角龙
Rank: 1
等 级:新手上路
帖 子:221
专家分:0
注 册:2006-5-5
收藏
得分:0 

Conatecate(&newhead1, &newtail2, &newhead2, &newtail2);
Conatecate(&newhead1, &newtail, &newhead2, &newtail2);

2变1就行了

奋斗改变一切!!
2006-05-27 12:19
快速回复:[求助]链表合并!找错误!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039353 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved