链表

本文介绍了链表的基本操作,包括删除指定位置的元素、在指定位置插入元素、查找特定元素的位置、初始化链表以及获取链表的长度等。通过这些操作,读者可以了解链表这一数据结构的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

## 链表的删除 ##
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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值