#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;
}