码迷,mamicode.com
首页 > 其他好文 > 详细

1.链表

时间:2017-06-06 22:17:42      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:ima   logs   .com   ring   简单   sizeof   turn   img   ges   

一.简单的静态链表

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#pragma warning(disable:4996)

typedef struct _Teacher
{
    char name[64];
    int age;
    struct _Teacher *next;

}Teacher;


int main()
{

    Teacher t1, t2, t3;

    memset(&t1,0,sizeof(Teacher));
    memset(&t2, 0, sizeof(Teacher));
    memset(&t3, 0, sizeof(Teacher));

    t1.next = &t2;
    t2.next = &t3;
    t3.next = NULL;

    t1.age = 20;
    t2.age = 30;
    t3.age = 40;

    Teacher *p = &t1;

    // 分别打印t1,t2,t3
    while (p)
    {
        printf("年龄为:%d\n",p->age);
        p = p->next;
    }

    system("pause");
    return 0;
}

输出:

技术分享

 

1.链表

标签:ima   logs   .com   ring   简单   sizeof   turn   img   ges   

原文地址:http://www.cnblogs.com/yongdaimi/p/6953427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!