栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言的链表尾插法,插入、删除等操作

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言的链表尾插法,插入、删除等操作

#include
#include

struct node{
    int data;
    struct node *next;
    
};

int main(){
    int i;
    struct node *head  =(struct node *)malloc(sizeof(struct node)),*p,*q,*r,*k,*w;
    q = head;
    k = head;
    for(i = 0; i < 10;i++){
        p = (struct node *)malloc(sizeof(struct node));
        p->data = i;
        q->next = p;
        q = p;
    }//链表尾插法 
    
q->next = NULL;

//链表的插入 
k = k->next;
    int n,t;scanf("%d %d",&n,&t);
    while(k != NULL){
        if(k->data == n){
            r = (struct node *)malloc(sizeof(struct node));w = (struct node *)malloc(sizeof(struct node));
            r->data = t;
            w = k->next;
            k->next = r;
            r->next = w;
            break;
        }
        k = k->next;
    }
    //链表的插入
    
    
//链表的删除 
    struct node *l,*m;
    l = head;
    l = l->next;
    while(l != NULL){
        if(l->next->data == n){
            m = l->next;
            l->next =m->next;
            free(m);
            break; 
            
        }
        l = l->next;
    }
//链表的删除 

//链表的建立 
    head = head->next;
    while(head != NULL){
        printf("%d ",head->data);
        head = head->next; 
    }
//链表的建立

    return 0;
};

​​​​​​​

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429500.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号