关闭

嵌入式 双向循环列表使用范例

472人阅读 评论(0) 收藏 举报
分类:
  1. #include
  2. #include
  3. #include
  4. //#include
  5. #define N 100
  6. //#define CHIN
  7. typedef structstudent
  8. {
  9. intstudentID;
  10. charname[N];
  11. intage;
  12. intsex;
  13. }STUDENT;
  14. typedef structscore
  15. {
  16. intchinese;
  17. intmath;
  18. intenglish;
  19. intaverage;
  20. inttotal;
  21. }SCORE;
  22. typedef structnode
  23. {
  24. STUDENT stu;
  25. SCORE sc;
  26. struct node*next;
  27. structnode *pione;
  28. }NODE;
  29. extern NODE *mycreate();
  30. externNODE * myinsert(NODE *,STUDENT *,SCORE *);
  31. extern void mycopy(NODE *,STUDENT *,SCORE*);
  32. externvoid myprint(NODE*);
  33. extern NODE *myremove(NODE **,int);
  34. externint Doublelinklistlen(NODE*);
  35. //extern NODE * mysearch(NODE*);
  36. //extern NODE *mysort(NODE *);
  37. extern void display(NODE *);
  38. externvoid addstudent(NODE*);
  39. extern void lookover(NODE *);
  40. externvoid deletestudent(NODE*);
  41. extern NODE *mysearch(NODE *,int);
  42. externvoid searchinfo(NODE*);
  43. //extern NODE *mysort(NODE*);
  44. //extern voidsortinfo(NODE *);
  45. extern void printnode(NODE *);
#include 
#include 
#include 
//#include 

#define N 100
//#define CHIN 

typedef struct student
{
    int studentID;
    char name[N];
    int age;
    int sex;
}STUDENT;

typedef struct score
{
    int chinese;
    int math;
    int english;
    int average;
    int total;
}SCORE;

typedef struct node
{
    STUDENT stu;
    SCORE sc;
    struct node *next;
    struct node *pione;
}NODE;

extern NODE * mycreate();
extern NODE * myinsert(NODE *,STUDENT *,SCORE *);
extern void mycopy(NODE *,STUDENT *,SCORE *);
extern void myprint(NODE *);
extern NODE * myremove(NODE **,int);
extern int Doublelinklistlen(NODE *);
//extern NODE * mysearch(NODE *);
//extern NODE * mysort(NODE *);
extern void display(NODE *);
extern void addstudent(NODE *);
extern void lookover(NODE *);
extern void deletestudent(NODE *);
extern NODE * mysearch(NODE *,int);
extern void searchinfo(NODE *);
//extern NODE *mysort(NODE *);
//extern void sortinfo(NODE *);
extern void printnode(NODE *);


StudentManage.c:

  1. #include"StudentManage.h"
  2. voidmycopy(NODE *node,STUDENT *student,SCORE*score)
  3. {
  4. node->stu.studentID =student->studentID;
  5. strcpy(node->stu.name,student->name);
  6. node->stu.age =student->age;
  7. node->stu.sex = student->sex;
  8. node->sc.chinese =score->chinese;
  9. node->sc.math = score->math;
  10. node->sc.english =score->english;
  11. node->sc.average = score->average;
  12. node->sc.total =score->total;
  13. }
  14. NODE * mycreate()
  15. {
  16. NODE *head = (NODE *)malloc(sizeof(NODE));
  17. head->stu.studentID = 0;
  18. head->next = head;
  19. head->pione = head;
  20. returnhead;
  21. }
  22. NODE * myinsert(NODE *head,STUDENT*student,SCORE *score)
  23. {
  24. if(head->stu.studentID ==0)
  25. {
  26. mycopy(head,student,score);
  27. }
  28. else
  29. {
  30. NODE *last = head;
  31. while(last->next !=head)
  32. {
  33. last = last->next;
  34. }
  35. NODE *p = (NODE *)malloc(sizeof(NODE));
  36. memset(p,0,sizeof(p));
  37. mycopy(p,student,score);
  38. head->pione = p;
  39. last->next = p;
  40. p->next = head;
  41. p->pione = last;
  42. }
  43. returnhead;
  44. }
  45. voidmyprint(NODE *head)
  46. {
  47. NODE *q = (NODE *)malloc(sizeof(NODE));
  48. q = head;
  49. int i =1;
  50. while(q->next !=head)
  51. //while(i <Doublelinklistlen(head))
  52. {
  53. 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);
  54. 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);
  55. i++;
  56. q = q->next;
  57. printf("\n");
  58. }
  59. 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);
  60. 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);
  61. }
  62. voidprintnode(NODE *node)
  63. {
  64. if(node !=NULL)
  65. {
  66. printf("ID:%d\tName:%s\tAge:%d\tSex:%d\n",node->stu.studentID,node->stu.name,node->stu.age,node->stu.sex);
  67. 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);
  68. }
  69. else
  70. {
  71. printf("");
  72. }
  73. printf("\n");
  74. }
  75. intDoublelinklistlen(NODE *head)
  76. {
  77. int len =0;
  78. NODE *q = head;
  79. while(q->next != head)
  80. {
  81. len++;
  82. q = q->next;
  83. }
  84. return (len +1);
  85. }
  86. NODE * myremove(NODE **head,int studentID)
  87. {
  88. //#define__DDD__
  89. NODE *q = (NODE *)malloc(sizeof(NODE));
  90. q = *head;
  91. int j =0;
  92. while(q->stu.studentID !=studentID)
  93. {
  94. j++;
  95. q = q->next;
  96. if(j >=Doublelinklistlen(*head))
  97. {
  98. #ifdef__DDD__
  99. printf("No Such Student has ThestudentID!\n");
  100. printf("Delete StudentFailure!\n");
  101. #endif
  102. return*head;
  103. }
  104. }
  105. NODE *pre = q->pione;
  106. NODE *ne = q->next;
  107. //pre->next = ne;
  108. //ne->pione =pre;
  109. if(q ==*head)
  110. {
  111. (*head) = (*head)->next;
  112. pre->next = (*head);
  113. (*head)->pione = pre;
  114. free(q);
  115. q = NULL;
  116. }
  117. else
  118. {
  119. pre->next = ne;
  120. ne->pione = pre;
  121. free(q);
  122. q = NULL;
  123. }
  124. #ifdef__DDD__
  125. printf("Delete StudentSuccess!\n");
  126. #endif
  127. return(*head);
  128. }
  129. NODE * mysearch(NODE *head,int info)
  130. {
  131. NODE *q = head;
  132. int j =0;
  133. #if 0
  134. int count =0;
  135. for(i = 0;i < Doublelinklistlen(head); i++)
  136. {
  137. if((num ==1) && (q->stu.studentID == (int)info))
  138. {
  139. printnode(q);
  140. count++;
  141. continue;
  142. }
  143. elseif((num == 2) &&(strcpy(q->stu.name,(char*)info) == 0))
  144. {
  145. printnode(q);
  146. count++;
  147. continue;
  148. }
  149. elseif((num == 3) &&(q->stu.age == (int)info))
  150. {
  151. printnode(q);
  152. count++;
  153. continue;
  154. }
  155. elseif((num == 4) &&(q->stu.sex == (int)info))
  156. {
  157. printnode(q);
  158. count++;
  159. continue;
  160. }
  161. else
  162. {
  163. ;
  164. }
  165. q = q->next;
  166. }
  167. if(count== 0)
  168. {
  169. printf("No infomationabout you input!\n");
  170. }
  171. #endif
  172. #if 1
  173. while(q->stu.studentID !=info)
  174. {
  175. j++;
  176. q = q->next;
  177. if(j >Doublelinklistlen(head))
  178. {
  179. printf("No ThisStudent!\n");
  180. returnNULL;
  181. }
  182. }
  183. //printnode(q);
  184. returnq;
  185. #endif
  186. }
  187. #if 0
  188. NODE * mysort(NODE *head)
  189. {
  190. NODE *newhead = mycreate();
  191. NODE *newlast = newhead;
  192. NODE *q = head;
  193. NODE *max = head;
  194. while(q !=NULL)
  195. {
  196. printf("%d\n",__LINE__);
  197. for(;q->next != head; q = q->next)
  198. {
  199. printf("%d\n",__LINE__);
  200. //sleep(2);
  201. if(q->next->sc.total >max->sc.total)
  202. {
  203. printf("%d\n",__LINE__);
  204. max = q->next;
  205. }
  206. }
  207. printf("%d\n",__LINE__);
  208. if(max ==head)
  209. {
  210. printf("%d\n",__LINE__);
  211. NODE * ne = head->next;
  212. NODE * pre = head->pione;
  213. head = head->next;
  214. ne->pione = pre;
  215. pre->next = ne;
  216. printf("%d\n",__LINE__);
  217. }
  218. else
  219. {
  220. printf("%d\n",__LINE__);
  221. NODE *ne = q->next;
  222. NODE *pre = q->pione;
  223. ne->pione = pre;
  224. pre->next = ne;
  225. printf("%d\n",__LINE__);
  226. }
  227. if(newhead->stu.studentID ==0)
  228. {
  229. printf("%d\n",__LINE__);
  230. newhead = max;
  231. newlast = max;
  232. printf("%d\n",__LINE__);
  233. }
  234. else
  235. {
  236. newlast->next = max;
  237. max->pione = newlast;
  238. max->next = newhead;
  239. newhead->pione = max;
  240. newlast = max;
  241. }
  242. q = q->next;
  243. }
  244. returnnewhead;
  245. }
  246. #endif
#include "StudentManage.h"

void mycopy(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;
    return head;
}

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;
    }
    return head;
}

void myprint(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);
}

void printnode(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");
}

int Doublelinklistlen(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 The studentID!\n");
            printf("Delete Student Failure!\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 Student Success!\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;
        }
        else if((num == 2) && (strcpy(q->stu.name,(char *)info) == 0))
        {
            printnode(q);
            count++;
            continue;
        }
        else if((num == 3) && (q->stu.age == (int)info))
        {
            printnode(q);
            count++;
            continue;
        }
        else if((num == 4) && (q->stu.sex == (int)info))
        {
            printnode(q);
            count++;
            continue;
        }
        else
        {
            ;
        }
        q = q->next;
    }
    if(count == 0)
    {
        printf("No infomation about you input!\n");
    }
    #endif
    #if 1
    while(q->stu.studentID != info)
    {
        j++;
        q = q->next;
        if(j > Doublelinklistlen(head))
        {
            printf("No This Student!\n");
            return NULL;
        }
    }
    //printnode(q);
    return q;
    #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;
    }
    return newhead;
}
#endif

Display.c:

  1. #include"StudentManage.h"
  2. voidaddstudent(NODE *head)
  3. {
  4. STUDENT stu;
  5. SCORE sc;
  6. printf("Please InputStudent's StudentID(12XXX):");
  7. scanf("%d",&stu.studentID);
  8. printf("Please InputStudent's Name:");
  9. scanf("%s",stu.name);
  10. printf("Please InputStudent's Age:");
  11. scanf("%d",&stu.age);
  12. printf("Please InputStudent's Sex(1:男 0:女):");
  13. scanf("%d",&stu.sex);
  14. printf("Please InputStudent's Chinese Score:");
  15. scanf("%d",&sc.chinese);
  16. printf("Please InputStudent's Math Score:");
  17. scanf("%d",&sc.math);
  18. printf("Please InputStudent's English Score:");
  19. scanf("%d",&sc.english);
  20. sc.average = (sc.chinese + sc.math +sc.english) / 3;
  21. sc.total = sc.chinese + sc.math + sc.english;
  22. system("clear");
  23. printf("The Infomation NewStudent:\n");
  24. printf("ID:%d\tName:%s\tAge:%d\tSex:%d\n",stu.studentID,stu.name,stu.age,stu.sex);
  25. printf("Chinese:m\tMath:m\tEnglish:m\n",sc.chinese,sc.math,sc.english);
  26. printf("Are You Sure ToAdd %d:%s ??(Y /N)",stu.studentID,stu.name);
  27. charch;
  28. scanf("\n%c",&ch);
  29. if(ch =='Y')
  30. {
  31. head = myinsert(head,&stu,&sc);
  32. printf("Add StudentSuccess!\n");
  33. }
  34. printf("Press Enter ToContinue...\n");
  35. getchar();
  36. getchar();
  37. }
  38. void lookover(NODE*head)
  39. {
  40. printf("The Infomation Of Student:\n");
  41. myprint(head);
  42. printf("Press Enter ToContinue...");
  43. getchar();
  44. getchar();
  45. }
  46. voiddeletestudent(NODE *head)
  47. {
  48. intid;
  49. #define __DDD__
  50. printf("Please Input TheStudentID Of Student You Want ToDelete(12XXX):");
  51. scanf("%d",&id);
  52. NODE *p = mysearch(head,id);
  53. printf("The Infomation NewStudent:\n");
  54. printnode(p);
  55. printf("Are You Sure To Add %d:%s??(Y /N)",p->stu.studentID,p->stu.name);
  56. charch;
  57. scanf("\n%c",&ch);
  58. if(ch== 'Y')
  59. {
  60. //head =myinsert(head,&stu,&sc);
  61. //printf("Add StudentSuccess!\n");
  62. //char ch;
  63. head = myremove(&head,id);
  64. }
  65. printf("Press Enter ToContinue...");
  66. getchar();
  67. getchar();
  68. }
  69. void searchinfo(NODE*head)
  70. {
  71. intn;
  72. //#define __DDD__
  73. printf("Please InputStudentID You Want ToSearch(12XXX):");
  74. scanf("%d",&n);
  75. NODE *p = mysearch(head,n);
  76. printnode(p);
  77. #if 0
  78. intn;
  79. intinfo;
  80. charname[N];
  81. printf("\n");
  82. printf("\n");
  83. printf("\n");
  84. printf("\n");
  85. printf("\n");
  86. printf("\n");
  87. printf("Please inputwhat you want to search:");
  88. scanf("%d",&n);
  89. while((n> 4) || (n < 1))
  90. {
  91. printf("Your input mustbe 1-4!\n");
  92. printf("Please inputagain:");
  93. scanf("%d",&n);
  94. }
  95. if(n ==1)
  96. {
  97. printf("Please inputStudeentID you want to search:");
  98. scanf("%d",&info);
  99. mysearch(head,1,info);
  100. }
  101. if(n ==2)
  102. {
  103. printf("Please inputStudeentName you want to search:");
  104. scanf("%s",name);
  105. mysearch(head,2,name);
  106. }
  107. if(n ==3)
  108. {
  109. printf("Please inputStudeentAge you want to search:");
  110. scanf("%d",&info);
  111. mysearch(head,3,info);
  112. }
  113. if(n ==4)
  114. {
  115. printf("Please inputStudeentSex you want to search:");
  116. scanf("%d",&info);
  117. mysearch(head,4,info);
  118. }
  119. #endif
  120. printf("Press Enter ToContinue...");
  121. getchar();
  122. getchar();
  123. }
  124. void display(NODE*head)
  125. {
  126. intchoose;
  127. while(1)
  128. {
  129. system("clear");
  130. printf("\n");
  131. printf("\n");
  132. printf("\n");
  133. printf("\n");
  134. //printf("\n");
  135. printf("\n");
  136. printf("\n");
  137. printf("\n");
  138. printf("Please Input YourChoose:");
  139. scanf("%d",&choose);
  140. while((choose > 5)|| (choose < 1))
  141. {
  142. printf("Your Choose Must Be 1 To5!\n");
  143. printf("Please InputYour Choose Again:");
  144. scanf("%d",&choose);
  145. }
  146. switch(choose)
  147. {
  148. case1:
  149. {
  150. system("clear");
  151. lookover(head);
  152. break;
  153. }
  154. case2:
  155. {
  156. system("clear");
  157. addstudent(head);
  158. break;
  159. }
  160. case3:
  161. {
  162. system("clear");
  163. deletestudent(head);
  164. break;
  165. }
  166. case4:
  167. {
  168. system("clear");
  169. searchinfo(head);
  170. break;
  171. }
  172. case5:
  173. {
  174. system("clear");
  175. exit(-1);
  176. }
  177. default:
  178. {
  179. break;
  180. }
  181. }
  182. }
  183. }
#include "StudentManage.h"

void addstudent(NODE *head)
{
    STUDENT stu;
    SCORE sc;
    printf("Please Input Student's StudentID(12XXX):");
    scanf("%d",&stu.studentID);
    printf("Please Input Student's Name:");
    scanf("%s",stu.name);
    printf("Please Input Student's Age:");
    scanf("%d",&stu.age);
    printf("Please Input Student's Sex(1:男 0:女):");
    scanf("%d",&stu.sex);
    printf("Please Input Student's Chinese Score:");
    scanf("%d",&sc.chinese);
    printf("Please Input Student's Math Score:");
    scanf("%d",&sc.math);
    printf("Please Input Student'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 New Student:\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 To Add %d:%s ??(Y / N)",stu.studentID,stu.name);
    char ch;
    scanf("\n%c",&ch);
    if(ch == 'Y')
    {
        head = myinsert(head,&stu,&sc);
        printf("Add Student Success!\n");
    }
    printf("Press Enter To Continue...\n");
    getchar();
    getchar();
}

void lookover(NODE *head)
{
    printf("The Infomation Of Student :\n");
    myprint(head);
    printf("Press Enter To Continue...");
    getchar();
    getchar();
}

void deletestudent(NODE *head)
{
    int id;
    #define __DDD__
    printf("Please Input The StudentID Of Student You Want To Delete(12XXX):");
    scanf("%d",&id);
    NODE *p = mysearch(head,id);
    printf("The Infomation New Student:\n");
    printnode(p);
    printf("Are You Sure To Add %d:%s ??(Y / N)",p->stu.studentID,p->stu.name);
    char ch;
    scanf("\n%c",&ch);
    if(ch == 'Y')
    {
        //head = myinsert(head,&stu,&sc);
        //printf("Add Student Success!\n");
    
    //char ch;
        head = myremove(&head,id);
    }
    printf("Press Enter To Continue...");
    getchar();
    getchar();
}

void searchinfo(NODE *head)
{
    
    int n;
    //#define __DDD__
    printf("Please Input StudentID You Want To Search(12XXX):");
    scanf("%d",&n);
    NODE *p = mysearch(head,n);
    printnode(p);
    #if 0
    int n;
    int info;
    char name[N];
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    printf("Please input what you want to search:");
    scanf("%d",&n);
    while((n > 4) || (n < 1))
    {
        printf("Your input must be 1-4!\n");
        printf("Please input again:");
        scanf("%d",&n);
    }
    if(n == 1)
    {
        printf("Please input StudeentID you want to search:");
        scanf("%d",&info);
        mysearch(head,1,info);
    }
    if(n == 2)
    {
        printf("Please input StudeentName you want to search:");
        scanf("%s",name);
        mysearch(head,2,name);
    }
    if(n == 3)
    {
        printf("Please input StudeentAge you want to search:");
        scanf("%d",&info);
        mysearch(head,3,info);
    }
    if(n == 4)
    { 
        printf("Please input StudeentSex you want to search:");
        scanf("%d",&info);
        mysearch(head,4,info);
    }
    #endif
    printf("Press Enter To Continue...");
    getchar();
    getchar();
}


void display(NODE *head)
{
    int choose;
    while(1)
    {
        system("clear");
        printf("\n");
        printf("\n");
        printf("\n");
        printf("\n");
        //printf("\n");
        printf("\n");
        printf("\n");
        printf("\n");
        printf("Please Input Your Choose:");
        scanf("%d",&choose);
        while((choose > 5) || (choose < 1))
        {
            printf("Your Choose Must Be 1 To 5!\n");
            printf("Please Input Your Choose Again:");
            scanf("%d",&choose);
        }
        switch(choose)
        {
            case 1:
            {
                system("clear");
                lookover(head);
                break;
            }
            case 2:
            {
                system("clear");
                addstudent(head);
                break;
            }
            case 3:
            {
                system("clear");
                deletestudent(head);
                break;
            }
            case 4:
            {
                system("clear");
                searchinfo(head);
                break;
            }
            case 5:
            {
                system("clear");
                exit(-1);
            }
            default:
            {
                break;
            }
        }

    }
}


main.c:

  1. #include"StudentManage.h"
  2. intmain()
  3. {
  4. NODE *head = mycreate();
  5. STUDENT stu1,stu2,stu3,stu4;
  6. SCORE sc1,sc2,sc3,sc4;
  7. stu1.studentID = 12001;
  8. strcpy(stu1.name,"王明");
  9. stu1.age = 18;
  10. stu1.sex = 1;
  11. sc1.chinese = 90;
  12. sc1.math = 91;
  13. sc1.english = 92;
  14. sc1.average = 91;
  15. sc1.total = 273;
  16. stu2.studentID = 12002;
  17. strcpy(stu2.name,"张芳");
  18. stu2.age = 19;
  19. stu2.sex = 0;
  20. sc2.chinese = 80;
  21. sc2.math = 81;
  22. sc2.english = 82;
  23. sc2.average = 81;
  24. sc2.total = 243;
  25. stu3.studentID = 12003;
  26. strcpy(stu3.name,"李强");
  27. stu3.age = 19;
  28. stu3.sex = 1;
  29. sc3.chinese = 70;
  30. sc3.math = 71;
  31. sc3.english = 72;
  32. sc3.average = 71;
  33. sc3.total = 213;
  34. stu4.studentID = 12004;
  35. strcpy(stu4.name,"张小雨");
  36. stu4.age = 20;
  37. stu4.sex = 0;
  38. sc4.chinese = 60;
  39. sc4.math = 61;
  40. sc4.english = 62;
  41. sc4.average = 61;
  42. sc4.total = 183;
  43. head =myinsert(head,&stu1,&sc1);
  44. head = myinsert(head,&stu2,&sc2);
  45. head =myinsert(head,&stu3,&sc3);
  46. head = myinsert(head,&stu4,&sc4);
  47. display(head);
  48. }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1051570次
    • 积分:18321
    • 等级:
    • 排名:第521名
    • 原创:741篇
    • 转载:523篇
    • 译文:0篇
    • 评论:105条
    最新评论