思维导图
作业
#include "head.h"
Double_Loop_Ptr Head_Create()
{
Double_Loop_Ptr H=(Double_Loop_Ptr)malloc(sizeof(Double_Loop));
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return NULL;
}
printf("The head of Double_Loop create successfully!\n");
H->len=0;
H->prev=H;
H->next=H;
return H;
}
Double_Loop_Ptr Regular_Node_Create(Datatype node_data)
{
Double_Loop_Ptr P=(Double_Loop_Ptr)malloc(sizeof(Double_Loop));
if(P==NULL)
return NULL;
P->data=node_data;
P->prev=NULL;
P->next=NULL;
return P;
}
int Double_Loop_Empty(Double_Loop_Ptr H)
{
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return -1;
}
return H->len==0;
}
void Last_Add(Double_Loop_Ptr H,Datatype add_data)
{
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return;
}
Double_Loop_Ptr P=Regular_Node_Create(add_data);
if(Double_Loop_Empty(H))
{
H->prev=P;
H->next=P;
P->prev=H;
P->next=H;
}
else
{
H->prev->next=P;
H->prev=P;
P->prev=H->prev;
P->next=H;
}
H->len++;
}
void Show_Double_Loop(Double_Loop_Ptr H)
{
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return;
}
else if(Double_Loop_Empty(H))
{
printf("The Double_Loop is empty!\n");
return;
}
else
{
printf("Travel successfully!\n");
Double_Loop_Ptr P=H->next;
int i=0;
while(P->next!=H)
{
i++;
printf("The %d node data is:%d\n",i,P->data);
P=P->next;
}
}
}
void Last_Delete(Double_Loop_Ptr H)
{
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return;
}
if(Double_Loop_Empty(H))
{
printf("The Double_Loop is empty!\n");
return;
}
Double_Loop_Ptr P=H;
if(H->len==1)
{
P=H->next;
H->prev=H;
H->next=H;
}
else
{
P=H->prev;
H->prev->prev->next=H;
H->prev=H->prev->prev;
}
free(P);
H->len--;
}
void Destroy_Double_Loop(Double_Loop_Ptr H)
{
if(H==NULL)
{
printf("The head of Double_Loop create failed!\n");
return;
}
while(!Double_Loop_Empty(H))
{
Last_Delete(H);
}
free(H);
printf("The Double_Loop has been destroyed!\n");
}