#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<malloc.h>
void InitLinkList (LinkList *head)
{
if(list == NULL) exit(0);
list->next = NULL;
}//初始化
static LinkList *ApplyNode(ElemType val,LinkList *next)
{
LinkList *s=(LinkList*)malloc(sizeof(LinkList));
if(s == NULL) exit(0);
s->data=val;
s->next=next;
return s;
}//创建新结点
void InterLinkList(LinkList *head,ElemType val,int pos)
if(list == NULL) exit(0);
if(pos<0)
{
printf("pos is error\n");
return;
}
LinkList *p = list;
while(pos && p!=NULL)
{
p=p->next;
pos--;
}
if(p==NULL)
{
printf("pos is error\n");
}
LinkList* NewNode(val, p->next)
if(NewNode == NULL) return;
p->next =NewNode;
}//按位置插入
void InterLinkListHead(LinkList*,ElemType val )
{
if(list == NULL) exit(0);
{
InterLinkList (list, val ,0);
}
}//头插
void InterLinkListTail(LinkList*,ElemType val)
{
if(list == NULL) exit(0);
LinkList *p=list;
while(p->next != NULL)
{
p=p->next;
}
LinkList *s = ApplyNode (val,NULL);
if(s ==NULL) exit(0);
p->next =s;
}//尾插
void ShowLinkList(LinkList*)
{
if(list == NULL) exit(0);
LinkList *p =list->next;
while(p != NULL)
{
printf("%d--\n",p->data);
p=p->next;
}
printf("%d\n");
}//Show
void DeleteLinkList(LinkList*list,int pos)
{
if(list == NULL) exit(0);
LinkList *p=list;
while(pos && p->next != NULL)
{
p=p->next;
pos--;
}
if(p->next = NULL) return;
LinkList *q =p->list;
p->next= q->list;
free(q);
}//按位置删除
void DeleteLinkListHead(LinkList*list)
{
if(list == NULL) exit(0);
DeleteLinkList (list,0);
}//头删
void DeleteLinkListTail(LinkList*list)
{
if(list == NULL) exit(0);
List*list *p=list;
LinkList *q=p->next;
while(q !=NULL && q->next !=NULL)
{
p=p->next;
q=q->next;
}
if(q == NULL) return;
p->next =NULL;
free(q);
}//尾删
void DestroyLinkList(LinkList*list)
{
if(list == NULL) exit(0);
LinkList *p=list;
while(p != NULL)
{
DeleteLinkListHead(list);
}
if(p ==NULL) exit(0);
}//销毁