Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void reg_student(slist *students, clist *courses, int id, int number){
- slist * temps=NULL,*temps2=NULL;
- clist * tempc=NULL,* tempc2=NULL;
- int in=1;
- for (;students->info->id!=id;students=students->next);
- for (;courses->info->number!=number;courses=courses->next);
- if (!(students->info->courses)){
- if(!(tempc=(clist*)malloc(sizeof(clist)))) exit(1);
- tempc->info=courses->info;
- tempc->next=NULL;
- students->info->courses=tempc;
- }
- else{
- tempc=students->info->courses;
- if (tempc->info->number>number){
- if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
- tempc2->info=courses->info;
- tempc2->next=tempc;
- students->info->courses=tempc2;
- in=0;
- }
- while (in){
- if (tempc->next && tempc->next->info->number>number){
- if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
- tempc2->next=tempc->next;
- tempc2->info=courses->info;
- tempc->next=tempc2;
- break;
- }
- if (!(tempc->next)){
- if (!(tempc2=(clist*)malloc(sizeof(clist)))) exit(1);
- tempc2->info=courses->info;
- tempc2->next=NULL;
- tempc->next=tempc2;
- break;
- }
- tempc=tempc->next;
- }
- }
- if (!(courses->info->students)){
- if(!(temps=(slist*)malloc(sizeof(slist)))) exit(1);
- temps->info=students->info;
- temps->next=NULL;
- courses->info->students=temps;
- }
- else{
- temps=courses->info->students;
- if (temps->info->id>id){
- if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
- temps2->info=students->info;
- temps2->next=temps;
- courses->info->students=temps2;
- return ;
- }
- while (1){
- if (temps->next && temps->next->info->id>id){
- if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
- temps2->next=temps->next;
- temps2->info=students->info;
- temps->next=temps2;
- return;
- }
- if (!(temps->next)){
- if (!(temps2=(slist*)malloc(sizeof(slist)))) exit(1);
- temps2->info=students->info;
- temps2->next=NULL;
- temps->next=temps2;
- return;
- }
- temps=temps->next;
- }
- }
- }
- void unreg_student(slist *students, int id, int number){
- clist * tempc;
- slist * temps;
- for (;students->info->id!=id;students=students->next);
- tempc=students->info->courses;
- for (;tempc->info->number!=number;tempc=tempc->next);
- temps=tempc->info->students;
- for (;temps->info->id!=id;temps=temps->next);
- tempc->info->students= remove_from_list_s(tempc->info->students,temps);
- students->info->courses= remove_from_list_c(students->info->courses,tempc);
- }
Add Comment
Please, Sign In to add comment