commit
This commit is contained in:
parent
bd738652a5
commit
031b51a916
10 changed files with 172 additions and 146 deletions
144
conf.c
144
conf.c
|
@ -21,7 +21,9 @@ int findConfId(ptConf confChain) {
|
|||
ptConf newConfChain() {
|
||||
ptConf confChain = (ptConf) malloc(sizeof(tConf));
|
||||
|
||||
confChain -> next = NULL;
|
||||
confChain -> next = (ptConf) malloc(sizeof(tConf));
|
||||
confChain -> next -> next = NULL;
|
||||
confChain -> id = -1;
|
||||
|
||||
return confChain;
|
||||
}
|
||||
|
@ -40,7 +42,9 @@ void addConf(ptConf confChain, int id, char title[], char speaker[], int day, in
|
|||
strcpy(px -> title, title);
|
||||
strcpy(px -> speaker, speaker);
|
||||
px -> listeners = (ptListenerList) malloc(sizeof(tListenerList));
|
||||
px -> listeners -> next = NULL;
|
||||
px -> listeners -> next = (ptListenerList) malloc(sizeof(tListenerList));
|
||||
px -> listeners -> listener = NULL;
|
||||
px -> listeners -> next -> next = NULL;
|
||||
px -> next = (ptConf) malloc(sizeof(tConf));
|
||||
px -> next -> next = NULL;
|
||||
}
|
||||
|
@ -48,44 +52,21 @@ void addConf(ptConf confChain, int id, char title[], char speaker[], int day, in
|
|||
void removeConf(ptConf confChain, int id) {
|
||||
ptConf px = confChain;
|
||||
|
||||
if (px -> next -> next == NULL) {
|
||||
ptListenerList py = px -> listeners;
|
||||
|
||||
while (py -> next != NULL) {
|
||||
ptConfList pz = py -> listener -> confs;
|
||||
|
||||
while (pz -> next != NULL) {
|
||||
if (pz -> next -> next )
|
||||
|
||||
pz = pz -> next;
|
||||
}
|
||||
|
||||
py = py -> next;
|
||||
}
|
||||
|
||||
while (px -> next != NULL && px -> next -> id != id) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
if (px -> next != NULL && px -> next -> id == id) {
|
||||
ptListenerList py = px -> next -> listeners -> next;
|
||||
|
||||
while (py -> next != NULL) {
|
||||
removeConfFromConfList(py -> listener -> confs, px -> next);
|
||||
py = py -> next;
|
||||
}
|
||||
|
||||
ptConf tmp = px -> next -> next;
|
||||
free(px -> next);
|
||||
px -> next = NULL;
|
||||
} else if (px -> id == id) {
|
||||
px -> id = px -> next -> id;
|
||||
strcpy(px -> title, px -> next -> title);
|
||||
strcpy(px -> speaker, px -> next -> speaker);
|
||||
px -> day = px -> next -> day;
|
||||
px -> month = px -> next -> month;
|
||||
px -> year = px -> next -> year;
|
||||
|
||||
ptConf tmp = px -> next;
|
||||
px -> next = px -> next -> next;
|
||||
free(tmp);
|
||||
} else {
|
||||
while (px -> next != NULL && px -> next -> id != id) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
if (px -> next -> id == id) {
|
||||
ptConf tmp = px -> next;
|
||||
px -> next = px -> next -> next;
|
||||
free(tmp);
|
||||
}
|
||||
px -> next = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +89,9 @@ ptListener newListenerChain() {
|
|||
ptListener listenerChain = (ptListener) malloc(sizeof(tListener));
|
||||
|
||||
listenerChain -> prev = NULL;
|
||||
listenerChain -> next = NULL;
|
||||
listenerChain -> next = (ptListener) malloc(sizeof(tListener));
|
||||
listenerChain -> next -> prev = listenerChain;
|
||||
listenerChain -> id = -1;
|
||||
|
||||
return listenerChain;
|
||||
}
|
||||
|
@ -129,7 +112,9 @@ int addListener(ptListener listenerChain, int id, char name[], int age, int leve
|
|||
px -> age = age;
|
||||
px -> level = level;
|
||||
px -> confs = (ptConfList) malloc(sizeof(tConfList));
|
||||
px -> confs -> next = NULL;
|
||||
px -> confs -> next = (ptConfList) malloc(sizeof(tConfList));
|
||||
px -> confs -> conf = NULL;
|
||||
px -> confs -> next -> next = NULL;
|
||||
px -> next = (ptListener) malloc(sizeof(tListener));
|
||||
px -> next -> next = NULL;
|
||||
px -> next -> prev = px;
|
||||
|
@ -139,30 +124,22 @@ int addListener(ptListener listenerChain, int id, char name[], int age, int leve
|
|||
void removeListener(ptListener listenerChain, int id) {
|
||||
ptListener px = listenerChain;
|
||||
|
||||
if (px -> next -> next == NULL) {
|
||||
while (px -> next != NULL && px -> next -> id != id) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
if (px -> next != NULL && px -> next -> id == id) {
|
||||
ptConfList py = px -> next -> confs -> next;
|
||||
|
||||
while (py -> next != NULL) {
|
||||
removeListenerFromListenerList(py -> conf -> listeners, px -> next);
|
||||
py = py -> next;
|
||||
}
|
||||
|
||||
ptListener tmp = px -> next -> next;
|
||||
free(px -> next);
|
||||
px -> next = NULL;
|
||||
} else if (px -> id == id) {
|
||||
px -> id = px -> next -> id;
|
||||
strcpy(px -> name, px -> next -> name);
|
||||
px -> age = px -> next -> age;
|
||||
px -> level = px -> next -> level;
|
||||
|
||||
ptListener tmp = px -> next;
|
||||
px -> next = px -> next -> next;
|
||||
px -> next = tmp;
|
||||
px -> next -> prev = px;
|
||||
free(tmp);
|
||||
} else {
|
||||
while (px -> next != NULL && px -> next -> id != id) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
if (px -> next -> id == id) {
|
||||
ptListener tmp = px -> next;
|
||||
px -> next = px -> next -> next;
|
||||
px -> next -> prev = px;
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +156,25 @@ void addConfToConfList(ptConfList confList, ptConf conf, int grade) {
|
|||
px -> next -> next = NULL;
|
||||
}
|
||||
|
||||
void removeConfFromConfList(ptConfList confList, ptConf conf) {
|
||||
ptConfList px = confList;
|
||||
|
||||
while (px -> next != NULL && px -> conf != conf) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
printConfList(confList -> next);
|
||||
printf("%d\n", px -> conf -> id);
|
||||
|
||||
if (px -> next != NULL && px -> next -> conf == conf) {
|
||||
ptConfList tmp = px -> next -> next;
|
||||
free(px -> next);
|
||||
px -> next = tmp;
|
||||
}
|
||||
|
||||
system("pause");
|
||||
}
|
||||
|
||||
void printConfList(ptConfList confList) {
|
||||
ptConfList px = confList;
|
||||
|
||||
|
@ -203,10 +199,24 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener,
|
|||
px -> next -> next = NULL;
|
||||
}
|
||||
|
||||
void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) {
|
||||
ptListenerList px = listenerList;
|
||||
|
||||
while (px -> next != NULL && px -> listener != listener) {
|
||||
px = px -> next;
|
||||
}
|
||||
|
||||
if (px -> next != NULL && px -> next -> listener == listener) {
|
||||
ptListenerList tmp = px -> next -> next;
|
||||
free(px -> next);
|
||||
px -> next = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void printListenerList(ptListenerList listenerList) {
|
||||
ptListenerList px = listenerList;
|
||||
|
||||
printf(" Participants : ");
|
||||
printf("Participants : ");
|
||||
while (px -> next != NULL) {
|
||||
printf("%s(%d) ", px -> listener -> name, px -> grade);
|
||||
px = px -> next;
|
||||
|
@ -227,7 +237,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in
|
|||
px = px -> next;
|
||||
}
|
||||
|
||||
pz = px -> listeners;
|
||||
pz = px -> listeners -> next;
|
||||
while (pz -> next != NULL) {
|
||||
if (pz -> listener -> id == listenerId) {
|
||||
return -2;
|
||||
|
@ -250,7 +260,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in
|
|||
}
|
||||
|
||||
int confGradeAvg(ptConf conf) {
|
||||
ptListenerList px = conf -> listeners;
|
||||
ptListenerList px = conf -> listeners -> next;
|
||||
int total = 0, nb = 0;
|
||||
|
||||
while (px -> next != NULL) {
|
||||
|
@ -268,7 +278,7 @@ int confGradeAvg(ptConf conf) {
|
|||
}
|
||||
|
||||
int confParticipations(ptConf conf) {
|
||||
ptListenerList px = conf -> listeners;
|
||||
ptListenerList px = conf -> listeners -> next;
|
||||
int nb = 0;
|
||||
|
||||
while (px -> next != NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue