- #include
- #include
- #include
- //#include
- #define N 100
- //#define CHIN
- typedef structstudent
- {
- intstudentID;
- charname[N];
- intage;
- intsex;
- }STUDENT;
- typedef structscore
- {
- intchinese;
- intmath;
- intenglish;
- intaverage;
- inttotal;
- }SCORE;
- typedef structnode
- {
- STUDENT stu;
- SCORE sc;
- struct node*next;
- structnode *pione;
- }NODE;
- extern NODE *mycreate();
- externNODE * myinsert(NODE *,STUDENT *,SCORE *);
- extern void mycopy(NODE *,STUDENT *,SCORE*);
- externvoid myprint(NODE*);
- extern NODE *myremove(NODE **,int);
- externint Doublelinklistlen(NODE*);
- //extern NODE * mysearch(NODE*);
- //extern NODE *mysort(NODE *);
- extern void display(NODE *);
- externvoid addstudent(NODE*);
- extern void lookover(NODE *);
- externvoid deletestudent(NODE*);
- extern NODE *mysearch(NODE *,int);
- externvoid searchinfo(NODE*);
- //extern NODE *mysort(NODE*);
- //extern voidsortinfo(NODE *);
- extern void printnode(NODE *);
StudentManage.c:
- #include"StudentManage.h"
- voidmycopy(NODE *node,STUDENT *student,SCORE*score)
- {
- node->stu.studentID =student->studentID;
- strcpy(node->stu.name,student->name);
- node->stu.age =student->age;
- node->stu.sex = student->sex;
- node->sc.chinese =score->chinese;
- node->sc.math = score->math;
- node->sc.english =score->english;
- node->sc.average = score->average;
- node->sc.total =score->total;
- }
- NODE * mycreate()
- {
- NODE *head = (NODE *)malloc(sizeof(NODE));
- head->stu.studentID = 0;
- head->next = head;
- head->pione = head;
- returnhead;
- }
- NODE * myinsert(NODE *head,STUDENT*student,SCORE *score)
- {
- if(head->stu.studentID ==0)
- {
- mycopy(head,student,score);
- }
- else
- {
- NODE *last = head;
- while(last->next !=head)
- {
- last = last->next;
- }
- NODE *p = (NODE *)malloc(sizeof(NODE));
- memset(p,0,sizeof(p));
- mycopy(p,student,score);
- head->pione = p;
- last->next = p;
- p->next = head;
- p->pione = last;
- }
- returnhead;
- }
- voidmyprint(NODE *head)
- {
- NODE *q = (NODE *)malloc(sizeof(NODE));
- q = head;
- int i =1;
- while(q->next !=head)
- //while(i <Doublelinklistlen(head))
- {
- printf("No.%d:ID:%d\tName:%s\tAge:%d\tSex:%d\n",i,q->stu.studentID,q->stu.name,q->stu.age,q->stu.sex);
- printf("Chinese:%d\tMath:%d\tEnglish:%d\tAverage:%d\tTotal:%d\n",q->sc.chinese,q->sc.math,q->sc.english,q->sc.average,q->sc.total);
- i++;
- q = q->next;
- printf("\n");
- }
- printf("No.%d:ID:%d\tName:%s\tAge:%d\tSex:%d\n",i,q->stu.studentID,q->stu.name,q->stu.age,q->stu.sex);
- printf("Chinese:%d\tMath:%d\tEnglish:%d\tAverage:%d\tTotal:%d\n",q->sc.chinese,q->sc.math,q->sc.english,q->sc.average,q->sc.total);
- }
- voidprintnode(NODE *node)
- {
- if(node !=NULL)
- {
- printf("ID:%d\tName:%s\tAge:%d\tSex:%d\n",node->stu.studentID,node->stu.name,node->stu.age,node->stu.sex);
- printf("Chinese:%d\tMath:%d\tEnglish:%d\tAverage:%d\tTotal:%d\n",node->sc.chinese,node->sc.math,node->sc.english,node->sc.average,node->sc.total);
- }
- else
- {
- printf("");
- }
- printf("\n");
- }
- intDoublelinklistlen(NODE *head)
- {
- int len =0;
- NODE *q = head;
- while(q->next != head)
- {
- len++;
- q = q->next;
- }
- return (len +1);
- }
- NODE * myremove(NODE **head,int studentID)
- {
- //#define__DDD__
- NODE *q = (NODE *)malloc(sizeof(NODE));
- q = *head;
- int j =0;
- while(q->stu.studentID !=studentID)
- {
- j++;
- q = q->next;
- if(j >=Doublelinklistlen(*head))
- {
- #ifdef__DDD__
- printf("No Such Student has ThestudentID!\n");
- printf("Delete StudentFailure!\n");
- #endif
- return*head;
- }
- }
- NODE *pre = q->pione;
- NODE *ne = q->next;
- //pre->next = ne;
- //ne->pione =pre;
- if(q ==*head)
- {
- (*head) = (*head)->next;
- pre->next = (*head);
- (*head)->pione = pre;
- free(q);
- q = NULL;
- }
- else
- {
- pre->next = ne;
- ne->pione = pre;
- free(q);
- q = NULL;
- }
- #ifdef__DDD__
- printf("Delete StudentSuccess!\n");
- #endif
- return(*head);
- }
- NODE * mysearch(NODE *head,int info)
- {
- NODE *q = head;
- int j =0;
- #if 0
- int count =0;
- for(i = 0;i < Doublelinklistlen(head); i++)
- {
- if((num ==1) && (q->stu.studentID == (int)info))
- {
- printnode(q);
- count++;
- continue;
- }
- elseif((num == 2) &&(strcpy(q->stu.name,(char*)info) == 0))
- {
- printnode(q);
- count++;
- continue;
- }
- elseif((num == 3) &&(q->stu.age == (int)info))
- {
- printnode(q);
- count++;
- continue;
- }
- elseif((num == 4) &&(q->stu.sex == (int)info))
- {
- printnode(q);
- count++;
- continue;
- }
- else
- {
- ;
- }
- q = q->next;
- }
- if(count== 0)
- {
- printf("No infomationabout you input!\n");
- }
- #endif
- #if 1
- while(q->stu.studentID !=info)
- {
- j++;
- q = q->next;
- if(j >Doublelinklistlen(head))
- {
- printf("No ThisStudent!\n");
- returnNULL;
- }
- }
- //printnode(q);
- returnq;
- #endif
- }
- #if 0
- NODE * mysort(NODE *head)
- {
- NODE *newhead = mycreate();
- NODE *newlast = newhead;
- NODE *q = head;
- NODE *max = head;
- while(q !=NULL)
- {
- printf("%d\n",__LINE__);
- for(;q->next != head; q = q->next)
- {
- printf("%d\n",__LINE__);
- //sleep(2);
- if(q->next->sc.total >max->sc.total)
- {
- printf("%d\n",__LINE__);
- max = q->next;
- }
- }
- printf("%d\n",__LINE__);
- if(max ==head)
- {
- printf("%d\n",__LINE__);
- NODE * ne = head->next;
- NODE * pre = head->pione;
- head = head->next;
- ne->pione = pre;
- pre->next = ne;
- printf("%d\n",__LINE__);
- }
- else
- {
- printf("%d\n",__LINE__);
- NODE *ne = q->next;
- NODE *pre = q->pione;
- ne->pione = pre;
- pre->next = ne;
- printf("%d\n",__LINE__);
- }
- if(newhead->stu.studentID ==0)
- {
- printf("%d\n",__LINE__);
- newhead = max;
- newlast = max;
- printf("%d\n",__LINE__);
- }
- else
- {
- newlast->next = max;
- max->pione = newlast;
- max->next = newhead;
- newhead->pione = max;
- newlast = max;
- }
- q = q->next;
- }
- returnnewhead;
- }
- #endif
Display.c:
- #include"StudentManage.h"
- voidaddstudent(NODE *head)
- {
- STUDENT stu;
- SCORE sc;
- printf("Please InputStudent's StudentID(12XXX):");
- scanf("%d",&stu.studentID);
- printf("Please InputStudent's Name:");
- scanf("%s",stu.name);
- printf("Please InputStudent's Age:");
- scanf("%d",&stu.age);
- printf("Please InputStudent's Sex(1:男 0:女):");
- scanf("%d",&stu.sex);
- printf("Please InputStudent's Chinese Score:");
- scanf("%d",&sc.chinese);
- printf("Please InputStudent's Math Score:");
- scanf("%d",&sc.math);
- printf("Please InputStudent's English Score:");
- scanf("%d",&sc.english);
- sc.average = (sc.chinese + sc.math +sc.english) / 3;
- sc.total = sc.chinese + sc.math + sc.english;
- system("clear");
- printf("The Infomation NewStudent:\n");
- printf("ID:%d\tName:%s\tAge:%d\tSex:%d\n",stu.studentID,stu.name,stu.age,stu.sex);
- printf("Chinese:m\tMath:m\tEnglish:m\n",sc.chinese,sc.math,sc.english);
- printf("Are You Sure ToAdd %d:%s ??(Y /N)",stu.studentID,stu.name);
- charch;
- scanf("\n%c",&ch);
- if(ch =='Y')
- {
- head = myinsert(head,&stu,&sc);
- printf("Add StudentSuccess!\n");
- }
- printf("Press Enter ToContinue...\n");
- getchar();
- getchar();
- }
- void lookover(NODE*head)
- {
- printf("The Infomation Of Student:\n");
- myprint(head);
- printf("Press Enter ToContinue...");
- getchar();
- getchar();
- }
- voiddeletestudent(NODE *head)
- {
- intid;
- #define __DDD__
- printf("Please Input TheStudentID Of Student You Want ToDelete(12XXX):");
- scanf("%d",&id);
- NODE *p = mysearch(head,id);
- printf("The Infomation NewStudent:\n");
- printnode(p);
- printf("Are You Sure To Add %d:%s??(Y /N)",p->stu.studentID,p->stu.name);
- charch;
- scanf("\n%c",&ch);
- if(ch== 'Y')
- {
- //head =myinsert(head,&stu,&sc);
- //printf("Add StudentSuccess!\n");
- //char ch;
- head = myremove(&head,id);
- }
- printf("Press Enter ToContinue...");
- getchar();
- getchar();
- }
- void searchinfo(NODE*head)
- {
- intn;
- //#define __DDD__
- printf("Please InputStudentID You Want ToSearch(12XXX):");
- scanf("%d",&n);
- NODE *p = mysearch(head,n);
- printnode(p);
- #if 0
- intn;
- intinfo;
- charname[N];
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("Please inputwhat you want to search:");
- scanf("%d",&n);
- while((n> 4) || (n < 1))
- {
- printf("Your input mustbe 1-4!\n");
- printf("Please inputagain:");
- scanf("%d",&n);
- }
- if(n ==1)
- {
- printf("Please inputStudeentID you want to search:");
- scanf("%d",&info);
- mysearch(head,1,info);
- }
- if(n ==2)
- {
- printf("Please inputStudeentName you want to search:");
- scanf("%s",name);
- mysearch(head,2,name);
- }
- if(n ==3)
- {
- printf("Please inputStudeentAge you want to search:");
- scanf("%d",&info);
- mysearch(head,3,info);
- }
- if(n ==4)
- {
- printf("Please inputStudeentSex you want to search:");
- scanf("%d",&info);
- mysearch(head,4,info);
- }
- #endif
- printf("Press Enter ToContinue...");
- getchar();
- getchar();
- }
- void display(NODE*head)
- {
- intchoose;
- while(1)
- {
- system("clear");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- //printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("Please Input YourChoose:");
- scanf("%d",&choose);
- while((choose > 5)|| (choose < 1))
- {
- printf("Your Choose Must Be 1 To5!\n");
- printf("Please InputYour Choose Again:");
- scanf("%d",&choose);
- }
- switch(choose)
- {
- case1:
- {
- system("clear");
- lookover(head);
- break;
- }
- case2:
- {
- system("clear");
- addstudent(head);
- break;
- }
- case3:
- {
- system("clear");
- deletestudent(head);
- break;
- }
- case4:
- {
- system("clear");
- searchinfo(head);
- break;
- }
- case5:
- {
- system("clear");
- exit(-1);
- }
- default:
- {
- break;
- }
- }
- }
- }
main.c:
- #include"StudentManage.h"
- intmain()
- {
- NODE *head = mycreate();
- STUDENT stu1,stu2,stu3,stu4;
- SCORE sc1,sc2,sc3,sc4;
- stu1.studentID = 12001;
- strcpy(stu1.name,"王明");
- stu1.age = 18;
- stu1.sex = 1;
- sc1.chinese = 90;
- sc1.math = 91;
- sc1.english = 92;
- sc1.average = 91;
- sc1.total = 273;
- stu2.studentID = 12002;
- strcpy(stu2.name,"张芳");
- stu2.age = 19;
- stu2.sex = 0;
- sc2.chinese = 80;
- sc2.math = 81;
- sc2.english = 82;
- sc2.average = 81;
- sc2.total = 243;
- stu3.studentID = 12003;
- strcpy(stu3.name,"李强");
- stu3.age = 19;
- stu3.sex = 1;
- sc3.chinese = 70;
- sc3.math = 71;
- sc3.english = 72;
- sc3.average = 71;
- sc3.total = 213;
- stu4.studentID = 12004;
- strcpy(stu4.name,"张小雨");
- stu4.age = 20;
- stu4.sex = 0;
- sc4.chinese = 60;
- sc4.math = 61;
- sc4.english = 62;
- sc4.average = 61;
- sc4.total = 183;
- head =myinsert(head,&stu1,&sc1);
- head = myinsert(head,&stu2,&sc2);
- head =myinsert(head,&stu3,&sc3);
- head = myinsert(head,&stu4,&sc4);
- display(head);
- }