C language for the data insertion, deletion, modification and other operations of the linked list

Preface

----- The last part talked about some related methods for the creation of linked lists, this content focuses on operations such as adding, deleting, checking and repairing linked lists

1. For the data insertion of the linked list

----- The insertion of linked list data first needs to obtain the inserted position information, and then locate the position through traversal, and insert the data:

Insert picture description here

The specific code is:

void InsertList(LinkList &L,int posData,int data) //PosData为数据data要插入位置,需要事先判断是否合法
{
    
    

    LNode *p=L,*alone;
    posData=posData-1;
    alone=(LinkList)malloc(sizeof(LNode));
    alone->i=data;
    while(p&&posData--)   //遍历来定位插入位置
    {
    
    
        p=p->next;
    }
    alone->next=p->next;
    p->next=alone;

}

Guess you like

Origin blog.csdn.net/xinzhilinger/article/details/109015516