插入
前插结点
bool InsertPriorNode(LNode *p, Elemtype e){
if(p == NULL)
return false;
LNode *s = (LNode*)malloc(sizeof(LNode));
s->next = p->next;
s->data = p->data;
p->next = s;
p->data = e;
return true;
}
后插结点
bool InsertNextNode(LNode *p, Elemtype e){
if(p == NULL)
return false;
LNode *s = (LNode*)malloc(sizeof(LNode));
if(s == NULL)
return false;
s->data = e;
s->next = p->next;
p->next = s;
return true;
}
按位插入元素
bool ListInsert(LinkList L, int pos){
if(pos < 1)
return false;
LNode *p = GetElem(L, pos-1);
return InsertNextNode(p, pos);
}
查找
按位查找
LNode * GetElem(LinkList L, int pos){
if(pos < 0){
return NULL;
}
int i = 0;
LNode *p;
p = L;
while(p != NULL && i < pos){
p = p->next;
i++;
}
return p;
}
按值查找
LNode * LocateElem(LinkList L, Elemtype e){
LNode *p;
p = L;
while (p != NULL && p->data != e){
p = p->next;
}
return p;
}
删除
按位删除
bool ListDelete(LinkList L, int pos, Elemtype *e){
if(pos < 1)
return false ;
LNode *p = GetElem(L, pos-1);
if(p == NULL)
return false;
if(p->next == NULL)
return false;
LNode *q = p->next;
e = q->data;
p->next = q->next;
free(q);
return true;
}
指定结点删除
bool DeleteNode(LNode *p){
if(p == NULL)
return false;
LNode *q = p->next;
p->data = p->next->data;
p->next = q->next;
free(q);
}
创建
尾插法
LinkList List_TailInsert(LinkList L){
L = (LinkList)malloc(sizeof(LNode