zoukankan      html  css  js  c++  java
  • 自引用结构--之链表指定值删除元素

    代码:

     1 //This is c program code!
     2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     3   * 文档信息: *** :~/testTmp4.c
     4   * 版权声明: *** :(魎魍魅魑)MIT
     5   * 联络信箱: *** :guochaoxxl@163.com
     6   * 创建时间: *** :2020年11月28日的上午10:18
     7   * 文档用途: *** :数据结构与算法分析-c语言描述
     8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
     9   * 修订时间: *** *2020年第47周 11月28日 星期六 下午09:00 (333天)
    10   * 文件描述: *** :自行添加
    11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    12 #include <stdio.h>
    13 #include <string.h>
    14 #include <stdlib.h>
    15 
    16 typedef struct _stu{
    17     char name[10];
    18     struct _stu *next;
    19 } Stu;
    20 
    21 int main(int argc, char **argv)
    22 {
    23     Stu *head;
    24     Stu *tmp;
    25     head = tmp = (Stu *)malloc(sizeof(Stu));
    26     tmp->next = NULL;
    27 
    28     char *stuName[] = {"lina", "mina", "bina", "tina", "dina"};
    29     int size = sizeof(stuName)/sizeof(stuName[0]);
    30 
    31     for(int i = 0; i < size; i++){
    32         strcpy(tmp->name, stuName[i]);
    33         Stu *tmpN = (Stu *)malloc(sizeof(Stu));
    34         tmpN->next = NULL;
    35         tmp->next = tmpN;
    36         tmp = tmpN;
    37     }
    38 
    39     printf("delete before: 
    ");
    40     Stu *head1 = head;
    41     for(int i = 0; i < size; i++){
    42         printf("%s
    ", head1->name);
    43         head1 = head1->next;
    44     }
    45 
    46     printf("delete 'bina' after: 
    ");
    47     Stu *head2 = head;
    48     tmp = head2;
    49     while(tmp->next != NULL){                                                           
    50         if(!(strcmp(tmp->next->name, "bina"))){
    51             tmp->next = tmp->next->next;
    52         }
    53         tmp = tmp->next;
    54     }
    55     while(NULL != head2->next){
    56         printf("%s
    ", head2->name);
    57         head2 = head2->next;
    58     }
    59 
    60     return 0;
    61 }

      代码简单,不多说了。

  • 相关阅读:
    javascript前端如何使用google-protobuf
    【Linux】Linux中常用操作命令
    MyEclipse 安装svn 插件步骤详情
    MultipartFile(文件的上传)--CommonsMultipartResolver
    oracle sql 获取本季度所有月份,上季度所有月份
    git与github安装、配置
    Java使用JaxWsDynamicClientFactory和HttpURLConnection两种方式调取webservice的接口
    三级联动
    Excel的两种导出入门方法(JAVA与JS)
    页面设置遮罩层
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/14054103.html
Copyright © 2011-2022 走看看