struct student
{
int num;
char name[10];
int grade;
}
按学生成绩等级将学生信息添加到相应等级的链表中。
#include
<
stdio.h
>
#include < stdlib.h >
#include < conio.h >
#define N 13
extern unsigned _floatconvert; /* 防止floating point formats not linked 错误发生 */
#pragma extref _floatconvert
typedef struct student
{
int num;
char name[ 10 ];
int grade;
}Stu;
Stu stu[N] = {{ 2 , " Lin " , 92 },
{ 3 , " Zhang " , 87 },
{ 4 , " Zhao " , 72 },
{ 5 , " Ma " , 91 },
{ 9 , " Zhen " , 85 },
{ 11 , " Wang " , 100 },
{ 12 , " Li " , 86 },
{ 13 , " Xu " , 83 },
{ 16 , " Mao " , 78 },
{ 17 , " Hao " , 95 },
{ 20 , " Lu " , 82 },
{ 21 , " Song " , 76 },
{ 22 , " Wu " , 88 }};
typedef struct node
{
Stu * data;
struct node * next;
}Node;
void show(Node * h)
{
Node * p;
p = h;
while (p -> next != NULL)
{
printf( " %d\t%s\t%d\n " ,p -> data -> num,p -> data -> name,p -> data -> grade);
p = p -> next;
}
}
void save(Node * h,Stu * p)
{
Node * s, * t;
s = (Node * )malloc( sizeof (Node));
t = h;
while (t -> next != NULL) t = t -> next;
s -> data = p;
s -> next = NULL;
t -> next = s;
}
void main()
{
int i,j,k,flag[ 4 ] = { 0 };
Node * h[ 4 ] = {NULL}, * p;
for (i = 0 ;i < N;i ++ )
for (j = 1 ;j < 4 ;j ++ )
{
k = 10 - int (stu[i].grade / 10 );
if (k == 0 ) k ++ ;
if (k == j)
if (flag[j] == 0 )
{
flag[j] = 1 ;
p = (Node * )malloc( sizeof (Node));
h[j] = p;
p -> data =& stu[i];
p -> next = NULL;
}
else
save(h[j], & stu[i]);
}
for (i = 1 ;i < 4 ;i ++ )
{
printf( " The NO.%d table:\n " ,i);
show(h[i]);
}
getch();
}
#include < stdlib.h >
#include < conio.h >
#define N 13
extern unsigned _floatconvert; /* 防止floating point formats not linked 错误发生 */
#pragma extref _floatconvert
typedef struct student
{
int num;
char name[ 10 ];
int grade;
}Stu;
Stu stu[N] = {{ 2 , " Lin " , 92 },
{ 3 , " Zhang " , 87 },
{ 4 , " Zhao " , 72 },
{ 5 , " Ma " , 91 },
{ 9 , " Zhen " , 85 },
{ 11 , " Wang " , 100 },
{ 12 , " Li " , 86 },
{ 13 , " Xu " , 83 },
{ 16 , " Mao " , 78 },
{ 17 , " Hao " , 95 },
{ 20 , " Lu " , 82 },
{ 21 , " Song " , 76 },
{ 22 , " Wu " , 88 }};
typedef struct node
{
Stu * data;
struct node * next;
}Node;
void show(Node * h)
{
Node * p;
p = h;
while (p -> next != NULL)
{
printf( " %d\t%s\t%d\n " ,p -> data -> num,p -> data -> name,p -> data -> grade);
p = p -> next;
}
}
void save(Node * h,Stu * p)
{
Node * s, * t;
s = (Node * )malloc( sizeof (Node));
t = h;
while (t -> next != NULL) t = t -> next;
s -> data = p;
s -> next = NULL;
t -> next = s;
}
void main()
{
int i,j,k,flag[ 4 ] = { 0 };
Node * h[ 4 ] = {NULL}, * p;
for (i = 0 ;i < N;i ++ )
for (j = 1 ;j < 4 ;j ++ )
{
k = 10 - int (stu[i].grade / 10 );
if (k == 0 ) k ++ ;
if (k == j)
if (flag[j] == 0 )
{
flag[j] = 1 ;
p = (Node * )malloc( sizeof (Node));
h[j] = p;
p -> data =& stu[i];
p -> next = NULL;
}
else
save(h[j], & stu[i]);
}
for (i = 1 ;i < 4 ;i ++ )
{
printf( " The NO.%d table:\n " ,i);
show(h[i]);
}
getch();
}