Guest User

Untitled

a guest
May 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. void reg_student(slist *students, clist *courses, int id, int number){
  2. slist * temps=NULL,*temps2=NULL;
  3. clist * tempc=NULL,* tempc2=NULL;
  4. int in=1;
  5. for (;students->info->id!=id;students=students->next);
  6. for (;courses->info->number!=number;courses=courses->next);
  7.  
  8. if (!(students->info->courses)){
  9. if(!(tempc=(clist*)malloc(sizeof(clist)))) exit(1);
  10. tempc->info=courses->info;
  11. tempc->next=NULL;
  12. students->info->courses=tempc;
  13. }
  14. else{
  15. tempc=students->info->courses;
  16. if (tempc->info->number>number){
  17. if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
  18. tempc2->info=courses->info;
  19. tempc2->next=tempc;
  20. students->info->courses=tempc2;
  21. in=0;
  22. }
  23. while (in){
  24. if (tempc->next && tempc->next->info->number>number){
  25. if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
  26. tempc2->next=tempc->next;
  27. tempc2->info=courses->info;
  28. tempc->next=tempc2;
  29. break;
  30. }
  31. if (!(tempc->next)){
  32. if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
  33. tempc2->info=courses->info;
  34. tempc2->next=NULL;
  35. tempc->next=tempc2;
  36. break;
  37. }
  38. tempc=tempc->next;
  39. }
  40. }
  41. if (!(courses->info->students)){
  42. if(!(temps=(slist*)malloc(sizeof(slist)))) exit(1);
  43. temps->info=students->info;
  44. temps->next=NULL;
  45. courses->info->students=temps;
  46. }
  47. else{
  48. temps=courses->info->students;
  49. if (temps->info->id>id){
  50. if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
  51. temps2->info=students->info;
  52. temps2->next=temps;
  53. courses->info->students=temps2;
  54. return ;
  55. }
  56. while (1){
  57. if (temps->next && temps->next->info->id>id){
  58. if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
  59. temps2->next=temps->next;
  60. temps2->info=students->info;
  61. temps->next=temps2;
  62. return;
  63. }
  64. if (!(temps->next)){
  65. if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
  66. temps2->info=students->info;
  67. temps2->next=NULL;
  68. temps->next=temps2;
  69. return;
  70. }
  71. temps=temps->next;
  72. }
  73. }
  74. }
  75. void unreg_student(slist *students, int id, int number){
  76. clist * tempc;
  77. slist * temps;
  78.  
  79. for (;students->info->id!=id;students=students->next);
  80. tempc=students->info->courses;
  81. for (;tempc->info->number!=number;tempc=tempc->next);
  82. temps=tempc->info->students;
  83. for (;temps->info->id!=id;temps=temps->next);
  84. tempc->info->students= remove_from_list_s(tempc->info->students,temps);
  85. students->info->courses= remove_from_list_c(students->info->courses,tempc);
  86. }
Add Comment
Please, Sign In to add comment