commit
This commit is contained in:
parent
63e83a9601
commit
bd738652a5
13 changed files with 1115 additions and 39 deletions
35
conf.c
35
conf.c
|
@ -49,6 +49,20 @@ 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;
|
||||
}
|
||||
|
||||
free(px -> next);
|
||||
px -> next = NULL;
|
||||
} else if (px -> id == id) {
|
||||
|
@ -99,7 +113,11 @@ ptListener newListenerChain() {
|
|||
return listenerChain;
|
||||
}
|
||||
|
||||
void addListener(ptListener listenerChain, int id, char name[], int age, int level) {
|
||||
int addListener(ptListener listenerChain, int id, char name[], int age, int level) {
|
||||
if (level < 0 || level > 5) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptListener px = listenerChain;
|
||||
|
||||
while (px -> next != NULL) {
|
||||
|
@ -115,6 +133,7 @@ void addListener(ptListener listenerChain, int id, char name[], int age, int lev
|
|||
px -> next = (ptListener) malloc(sizeof(tListener));
|
||||
px -> next -> next = NULL;
|
||||
px -> next -> prev = px;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void removeListener(ptListener listenerChain, int id) {
|
||||
|
@ -187,7 +206,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener,
|
|||
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;
|
||||
|
@ -195,7 +214,11 @@ void printListenerList(ptListenerList listenerList) {
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
void participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) {
|
||||
int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) {
|
||||
if (grade < 0 || grade > 5) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptConf px = confChain;
|
||||
ptListener py = listenerChain;
|
||||
ptListenerList pz;
|
||||
|
@ -207,7 +230,7 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
|
|||
pz = px -> listeners;
|
||||
while (pz -> next != NULL) {
|
||||
if (pz -> listener -> id == listenerId) {
|
||||
return;
|
||||
return -2;
|
||||
}
|
||||
pz = pz -> next;
|
||||
}
|
||||
|
@ -217,11 +240,13 @@ void participateToConf(ptConf confChain, ptListener listenerChain, int confId, i
|
|||
}
|
||||
|
||||
if (px -> id != confId || py -> id != listenerId) {
|
||||
return;
|
||||
return -2;
|
||||
}
|
||||
|
||||
addListenerToListenerList(px -> listeners, py, grade);
|
||||
addConfToConfList(py -> confs, px, grade);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int confGradeAvg(ptConf conf) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue