📄 manage.c
字号:
#include "stdio.h"
#define LEN sizeof(struct student)
#define TURE 1
struct student
{ unsigned long num;
float score;
struct student *next;
};
extern struct student *head;
/*create the list*/
Creat()
{
struct student *p1,*p2;
unsigned long num;
float score;
int key;
head=NULL;
printf("\nCreate New information(Y/N)?");
while(bioskey(1)==0);
key=Getkey();
if(key!=0x15)return;
printf("\nPlease Input Information Of Students:\n");
p1=p2=(struct student * )malloc(LEN);
if(p1==NULL){ printf("No buf!");return;}
printf("Number:");
scanf("%lu",&num);
p1->num=num;
printf("Score:");
scanf("%f",&score);
p1->score=score;
head=p1;
p2=p1;
printf("Continue?(Y/N):");
while(bioskey(1)==0);
key=Getkey();
if(key!=0x15){p2->next=NULL;return;}
do
{
p1=(struct student*)malloc(LEN);
printf("\nPlease Input Information Of Students:\n");
cprintf("Number:");
scanf("%lu",&(p1->num));
cprintf("Score:");
scanf("%f",&(p1->score));
p2->next=p1;p2=p1;
printf("Continue?(Y/N):");
while(bioskey(1)==0);
key=Getkey();
}while(key==0x15);
p2->next=NULL;
printf("%lu,%f",head->num,head->score);
getch();
}
/*insert in list*/
Insert()
{
struct student *p1, *p2;
int key;
for(p2=head;p2->next!=NULL;p2=p2->next);
do
{
p1=(struct student*)malloc(LEN);
printf("Please Input Information Of Students to Insert:\n");
printf("Number:");
scanf("%lu",&(p1->num));
printf("Score:");
scanf("%f",&(p1->score));
if(head==NULL)
{
head=p1;
p1->next=NULL;
}
else
{ p2->next=p1;
p2=p1;
}
printf("Continue?(Y/N):");
while(bioskey(1)==0);
key=Getkey();
}while(key==0x15);
p2->next=NULL;
}
/*delete a node*/
Del()
{
struct student *p1,*p2;
unsigned long num;
int key;
if(head==NULL)
{
printf("List null!\n");
return;
}
p1=head;
do
{
printf("Input the Number to Delete:");
scanf("%lu",&num);
while(p1->num!=num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("\nDelete:%luOK!\n",num);
free(p1);
}
else
printf("\nThe %lu Not been Found!\n",num);
printf("Continue?(Y/N):");
while(bioskey(1)==0);
key=Getkey();
}while(key==0x15);
}
/*find a node in the list*/
Find()
{
struct student *p1;
unsigned long num;
if(head==NULL)
{
printf("\n List null!\n");
return;
}
printf("\nInput the Number to Find:");
scanf("%lu",&num);
p1=head;
printf("%lu,%f",head->num,head->score);
getch();
while(num!=p1->num&&p1->next!=NULL)p1=p1->next;
if(num==p1->num)
printf("\nFind! Num:%lu, Score=%5.2f\n",num,p1->score);
else
printf("\nThe %lu not been Found!\n",num);
}
/*print the list*/
void Print()
{
struct student *p;
int n=0;
for(p=head;p!=NULL;p=p->next,n++);
printf("\n Now,these %d records are:\n",n);
p=head;
if(head==NULL)
{
printf("\nNO Stu Infor!\n");
return;
}
printf("\nNum Score\n");
do
{ printf("%-15lu",p->num,p->score);
printf("%f\n",p->score);
p=p->next;
}while(p!=NULL);
}
/*void Help()
{
printf("\n c Creat a list(Print 0 when you creat end)");
printf("\n d Delete a node from the list");
printf("\n f Find a node in the list");
printf("\n i Insert a node to the list");
printf("\n p Print the list");
printf("\n q Quit from the program.\n");
}
main()
{
struct student *q,*qtemp,*instu;
unsigned long tempnum;
q=NULL;
printf("\n Please chose one operation(Type h for help):");
do{
switch(getchar())
{
case'c': printf("Please input the data of list,format is'num,score':\n");
q=creat();
break;
case'd': qtemp=q;
if(qtemp!=NULL)
{printf("\n Please input the num which you want to del in the list:\n");
scanf("%ld",&tempnum);
}
q=del(qtemp,tempnum);
qtemp=NULL;
tempnum=0;
break;
case'f': qtemp=q;
if(qtemp!=NULL)
{
printf("\n Please input the num which you want to find in the list:\n");
scanf("%ld",&tempnum);
}
q=find(qtemp,tempnum);
qtemp=NULL;
tempnum=0;
break;
case'i': qtemp=q;
printf("\n Please input the node which you want to insert:\n");
instu=(struct student*)malloc(LEN);
scanf("%ld,%f",&instu->num,&instu->score);
q=insert(qtemp,instu);
qtemp=NULL;
break;
case'p': qtemp=q;
if(qtemp!=NULL)
{
printf("\n---------list--------");
print(qtemp);
printf("-----------------\n");
}
else
printf("\n there isn't any list,please creat one\n");
qtemp=NULL;
break;
case'h': help();break;
case'q': exit(0);
default: printf("\n Please chose one operation.");
printf("\n Only c,d,f,h,i,p,q can be chose(Type h for help):");
break;
}
}while(TURE);
}*/
/*Creat()
{
gotoxy(1,2);
printf("Please input the data of list,format is'num,score':\n");
head=creat();
}
Del()
{
struct student *qtemp;
unsigned long tempnum;
qtemp=head;
if(qtemp!=NULL)
{
gotoxy(1,2);
printf("\n Please input the num which you want to del in the list:\n");
scanf("%ld",&tempnum);
}
head=del(qtemp,tempnum);
}
Find()
{
struct student *qtemp;
unsigned long tempnum;
qtemp=head;
if(qtemp!=NULL)
{
gotoxy(1,2);
printf("\n Please input the num which you want to find in the list:\n");
scanf("%ld",&tempnum);
}
head=find(qtemp,tempnum);
qtemp=NULL;
tempnum=0;
}
Insert()
{
struct student *qtemp,*instu;
unsigned long tempnum;
qtemp=head;
gotoxy(1,2);
printf("\n Please input the node which you want to insert:\n");
instu=(struct student*)malloc(LEN);
scanf("%ld,%f",&instu->num,&instu->score);
head=insert(qtemp,instu);
qtemp=NULL;
}
Print()
{
struct student *qtemp;
unsigned long tempnum;
qtemp=head;
gotoxy(1,2);
if(qtemp!=NULL)
{
printf("\n---------list--------");
print(qtemp);
printf("-----------------\n");
}
else
printf("\n there isn't any list,please creat one\n");
qtemp=NULL;
} */
Help()
{
gotoxy(1,2);
printf("help!");
/*Clr();*/
}
Load()
{
gotoxy(1,2);
printf("No File!");
/*Clr();*/
}
Other()
{
gotoxy(1,2);
printf("Other!");
/*Clr();*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -