首页 > 其他 > 详细

C 创建链表

时间:2016-10-23 11:57:32      阅读:196      评论:0      收藏:0      [点我收藏+]

#include<malloc.h>
#include<stdio.h>
#define LEN sizeof(struct student)
typedef struct student
{
int num;
int age;
float score;
struct student *next;
}stu;
int n;
stu *creat(void)
{
stu *struHead;
stu *struP1;
stu *struP2;
n = 0;
struP1 = struP2 = ( stu *)malloc( LEN );
scanf("%d,%d,%f", &struP1->num, &struP1->age, &struP1->score);
struHead = NULL;
while( struP1->num != 0 )
{
n = n + 1;
if( n == 1 )
{
struHead = struP1;
}
else
{
struP2->next = struP1;
}
struP2 = struP1;
struP1 = ( stu *)malloc( LEN );
scanf("%d,%d,%f", &struP1->num, &struP1->age, &struP1->score);
}
struP2->next = NULL;
return( struHead );
}
void main()
{
stu *p;
stu *head;
head = creat();
p = head;
if( head != NULL )
do
{
printf( "%d,%d,%f\n", p->num, p->age, p->score);
p = p->next;

}while( p != NULL );

}

C 创建链表

原文:http://www.cnblogs.com/lanlianggui/p/5989122.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!