|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题 , 就是小甲鱼老师的结构体第三课课后作业 建立一个动态链表 , 我自己写了一个和答案不一样 但是也可以做出来,同样 我也没有使用malloc 函数 ,感觉小甲鱼老师的答案有些复杂, 不知道这样的思路对不对 各位帮着看一看 谢谢
#include <stdio.h>
struct student
{
long num;
float score;
struct student *next;
};
void main()
{
struct student student1 , *p1 , *p2 ,*head;
int n = 0;
p1 = &student1;
p2 = &student1;
do
{
printf("please input the number of this student:\t");
scanf("%ld",&p1->num);
printf("please input the score of this student : \t");
scanf("%f",&p1->score);
puts("\n");
if(p1->num != 0)
{
n = n + 1;
if(n ==1)
{
head = p1;
}
else if(n != 1)
{
p2->next = p1;
}
p2 = p1;
}
else if(p1->num == 0)
{
p2->next = NULL;
}
printf("This is the %d st student the number of student is :\t%ld and his / her score is :\t%f\n",n ,p1->num,p1->score);
puts("***************************************************************************");
puts("\n");
}
while(p2->next != NULL);
printf("\n\nthe school is %d student\n",n);
}
|
|