zoukankan      html  css  js  c++  java
  • 单链表节点的删除

                                                                                                   单链表节点的删除
    删除单链表pos位置的节点,返回头指针
    pos从开始计算,1表示删除head后面的第一个节点
    node *delete_node(node *head,int pos)
    {
    node *item=NULL;
    node *p=head->next;
    if(p==NULL)
    {
    printf("link is empty ");
    return NULL;
    }
    p=search_node(head,pos-1);//获得位置pos的节点指针
    if(p!=NULL && p->next!=NULL)
    {
    item=p->next;
    p->next=item->next;
    delete item;
    }
    return head;
    }
      
    main()
    {
    node *head=create();//创建单链表(创建函数的实现见我的博客)
    printf("Length:%d ",length(head));//测单链表的长度
    head=insert_node(head,2,5);//在第二个节点的后面添加5
    printf("insert integer 5 after 2th node: ");
    printf(node);//打印单链表
    head=delete_node(head,2);删除第二个节点
    printf("delete the 2th node ");
    print(head);
    }
  • 相关阅读:
    python--执行文件的绝对路径
    python----slots属性安全类
    linux----LAMP之编译安装apache
    MySQL----alter table modify | change的不同
    数据库5
    数据库4
    数据库3
    数据库2
    数据库1
    MySQL exists 和 not exists 的用法
  • 原文地址:https://www.cnblogs.com/zhangaihua/p/3718072.html
Copyright © 2011-2022 走看看