## 链表的删除 ##
void list_delete(node * L, int i)
{
node * u;
node * P = L;
int k = 0;
while (k != i - 1 && P! = NULL)
{
P = P->next;
k++;
}
if (P = NULL || P->next == NULL)
ERROR("删除序号错");
else
{
u = P->next;
P->next = u->next;
delete u;
}
}
## 插入节点 ##
void list_insert(node * L, int i, int x)
{
node * P = L;
int k = 0;
node * S;
while (k!=i-1&&P!=NULL)
{
P = P->next;
k++;
}
if (P = NULL)
ERROR("序号错");
else
{
S = new node;
S->data = x;
S->next = P->next; P->next = S;//插入节点。
}
}
## 查找运算 ##
“`
node * list_locate(node *L, int x)
{
node *P = L->next;
while (P!=NULL&&P->data!=x)
P = P->next;
return P;
}
## 初始化链表 ##
void inital_list(node *&L)
{
L = new node;
L->next = NULL;
}
## 链表长度 ##
int list_length(node * L)
{
int n = 0;
node *P = L->next;
while (P != NULL)
{
n++;
P = P->next;
}
return n;
}