首先我会把你放在上下文中
我们有一个有序列表(TAD JuryList)来存储不同的陪审团:
typedef struct tItemJ{
tJuryName juryName;
tNumVotes totalVoters;
tNumVotes validVotes;
tNumVotes nullVotes;
tListP participantList;
}tItemJ;
typedef int tPosJ;
typedef struct {
tItemJ data[MAX];
tPosJ lastPos;
}tListJ;
void createEmptyListJ(tListJ *L);
bool isEmptyListJ(tListJ L);
tPosJ firstJ(tListJ L);
tPosJ lastJ(tListJ L);
tPosJ nextJ(tPosJ p, tListJ L);
tPosJ previousJ(tPosJ p, tListJ L);nsertItemJ(tItemJ d, tListJ *L);
void deleteAtPositionJ(tPosJ p, tListJ *L);
tItemJ getItemJ(tPosJ p, tListJ L);
void updateItemJ(tItemJ d, tPosJ p, tListJ *L);
tPosJ findItemJ(tJuryName t, tListJ L);
我们还有以下规范,一个有序列表(TAD ParticipantList),用于存储与单个陪审团相对应的参与者的选票:
#ifndef PARTICIPANT_LIST_H
#define PARTICIPANT_LIST_H
#include "types.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NULLP NULL
typedef struct tNode *tPosP;
typedef struct tItemP{
tParticipantName participantName;
tNumVotes numVotes;
tEUParticipant euParticipant;
}tItemP;
struct tNode{
tItemP data;
tPosP next;
};
typedef tPosP tListP;
void createEmptyListP(tListP *L);
bool isEmptyListP(tListP L);
tPosP firstP(tListP L);
tPosP lastP(tListP L);
tPosP nextP(tPosP p, tListP L);
tPosP previousP(tPosP p, tListP L);
bool insertItemP(tItemP d, tListP *L);
void deleteAtPositionP(tPosP p, tListP *L);
tItemP getItemP(tPosP p, tListP L);
void updateItemP(tItemP d, tPosP p, tListP *L);
tPosP findItemP(tParticipantName t, tListP L);
#endif
我们要执行操作
New
,其参数为void New(char *juryName, char *participantName, char *EUparticipant, tListJ *L)
, 它注册了陪审团的参与者并且有 0 票。
EUParticipant
可以取值 eu 或 non-eu。
而函数的解释如下:
如果操作是[N]ew
,参与者将被添加到指定的陪审团中,并显示以下内容:
New: jury XX participant YY location ZZ
其中
XX
是陪审团的名字,YY
是参与者的名字,ZZ
是 EUParticipant 的值
(欧盟或非欧盟将根据布尔值打印)。如果该参与者已经存在于
陪审团或插入时出现问题,它将显示:
+Error: New not possible
所以我做了这样的功能:
tItemP participants(char *EUparticipant){
tItemP d;
if(strcmp(EUparticipant, "eu")==0){
d.euParticipant = 0;
return d;
}else{
d.euParticipant = 1;
return d;
}
}
void New(char *juryName, char *participantName, char *EUparticipant, tListJ *L){
tPosJ jury;
tItemP newParticipant;
tListP participant;
tPosP pParticipant;
jury = findItemJ(juryName, *L); //Buscamos si el jurado existe en la lista de jurados
if (jury != NULLJ) { //Si existe
participant = getItemJ(jury, *L).participantList;
pParticipant = findItemP(participantName, participant);
if ( pParticipant== NULLP) {
strcpy(newParticipant.participantName, participantName);
newParticipant.numVotes = 0;
newParticipant.euParticipant = participants(EUparticipant).euParticipant;`
if (insertItemP(newParticipant, &participant)) {
printf("New: jury %s participant %s location %s\n", juryName, participantName, EUparticipant);
} else { //si hubo algún error al insertar
printf("+ Error: New not possible\n");
}
} else { //Si el participante ya existe
printf("+ Error: New not possible\n");
}
} else { //Si el jurado no existe
printf("+ Error: New not possible\n");
}
}
但是我在 findItemP 中有一个 sementation 错误,我不知道如何修复它,有人可以帮助我吗?