代码如下:
#include"stdio.h"
#include"stdlib.h"
#include"windows.h"
//#define MUN 4
//#define SEC 5
#define NAM 20
#define SEX 4
void print(struct student* head);
struct student
{
int munber;
int sec;
char name[NAM];
char sex[SEX];
char end;
student *next;
};
struct student *head=NULL;
struct student *p1,*p2;
void enter()
{
printf("请输入学号:");
scanf_s("%d",&p1->munber);
printf("请输入成绩:");
scanf_s("%d",&p1->sec);
fflush(stdin);
printf("请输入姓名:");
gets_s(p1->name);
fflush(stdin);
printf("请输入性别:");
gets_s(p1->sex);
fflush(stdin);
printf("是否继续输入?(按“Y“继续,其他键停止输入)");
p1->end=getchar();
fflush(stdin);
printf("===================================================\n");
}
int main(void)
{
system("color F0");
p1=(student*)malloc(sizeof(student));
head=p1;
p2=p1;
enter();
p1->next=NULL;
while(p1->end=='Y'||p1->end=='y')
{
p2=p1;
p1=(student*)malloc(sizeof(student));
enter();
p2->next=p1;
}
p1->next=NULL;
print(head);
return 0;
}
void print(struct student *head)
{
struct student *temp;
temp=head;
printf("学号\t姓名\t成绩\t性别\t\n");
while(temp!=NULL)
{
printf("%d\t%s\t%d\t%s\n",temp->munber,temp->name,temp->sec,temp->sex);
temp=temp->next;
}
}
补充:
请问怎么删除节点,插入节点,和修改节点呢?头节点该怎么设计才能实现这些呢?