#include <stdio.h>
#include <stdlib.h>
#include "2.h"
Linklist* create_link()
{
Linklist* head=(Linklist*)malloc(sizeof(Linklist));
if(NULL == head)
{
printf("创建失败\n");
return NULL;
}
head->txt.len=0;
head->next=head;
return head;
}
void Head_insertion(Linklist* head, dataType num)
{
Linklist* temp=(Linklist*)malloc(sizeof(Linklist));
if(NULL == temp)
{
printf("创建失败\n");
return;
}
temp->txt.data=num;
temp->next = NULL;
temp->next=head->next;
head->next=temp;
head->txt.len++;
return;
}
void Tail_insertion(Linklist* head, dataType num)
{
Linklist* temp=(Linklist*)malloc(sizeof(Linklist));
if(NULL == temp)
{
printf("创建失败\n");
return;
}
temp->txt.data=num;
temp->next = NULL;
Linklist* p;
p=head;
while(p->next != head)
{
p=p->next;
}
temp->next=p->next;
p->next=temp;
head->txt.len++;
return;
}
void Head_deletion(Linklist* head)
{
if(head->next == head)
{
printf("删除失败\n");
return;
}
Linklist* temp=head->next;
head->next=temp->next;
free(temp);
head->txt.len--;
}
void Tail_deletion(Linklist* head)
{
if(head->next == head)
{
printf("删除失败\n");
return;
}
Linklist* p=head;
while(p->next->next != head)
{
p=p->next;
}
Linklist* temp=p->next;
p->next=temp->next;
free(temp);
head->txt.len--;
return;
}
void show_Linklist(Linklist* head)
{
Linklist* p=head;
while(p->next != head)
{
p=p->next;
printf("%d\t",p->txt.data);
}
printf("\n");
return;
}