zoukankan      html  css  js  c++  java
  • [代码记录] C语言链表

    #开始

    ·  简单的创建链表

    #代码

      

     1 #include<conio.h>
     2 #include<stdio.h>
     3 #include<stdlib.h>
     4 
     5 struct Str
     6 {
     7     char name[100];
     8     int sex;
     9     int id;
    10     Str * next;
    11 };
    12 
    13 void printStruct(Str *str)    //输出链表
    14 {
    15     Str *strTemp = str;
    16     while(strTemp->next)
    17     {
    18         printf("=========print=============
    ");
    19         printf("id: %d
    ",strTemp->id);
    20         printf("name: %s
    ",strTemp->name);
    21         printf("sex: %d
    ",strTemp->sex);
    22         strTemp = strTemp->next;
    23     }
    24 }
    25 
    26 int main()
    27 {
    28     Str* strFirst = (Str*)malloc(sizeof(Str));
    29     Str* strTemp = strFirst;
    30     while(strTemp->next)    //创建链表
    31     {
    32         printf("=========================
    ");
    33         printf("输入id:");
    34         scanf("%d",&strTemp->id);
    35         if(strTemp->id == 0)    //如果输入id == 0 就退出输入
    36         {
    37             strTemp->next = NULL;    //给next赋值NULL 并且返回到循环的最开始的位置
    38             continue;
    39         }
    40         printf("输入name:");
    41         scanf("%s",strTemp->name);
    42 
    43         printf("输入sex:");
    44         scanf("%d",&strTemp->sex);
    45 
    46         strTemp->next=(Str*)malloc(sizeof(Str)); 
    47         strTemp = strTemp->next;
    48     }
    49     printStruct(strFirst);    //输出链表
    50 
    51     _getch();
    52     return 0;
    53 }

    #运行环境

      win7 32位

      VS2010 

  • 相关阅读:
    线程生命周期
    java集合源码分析几篇文章
    Java中的equals和hashCode方法详解
    java集合(一)
    volatile和synchronized实现内存可见性的区别
    动态代理的原理
    过滤器的使用
    pageBean的实体类
    FindUserByPageServlet
    用户信息系统_serviceImpl
  • 原文地址:https://www.cnblogs.com/cjdty/p/9602640.html
Copyright © 2011-2022 走看看