int findRec(dbkeytype key, dbdatatype *data, indextype *idx) { Dbrec rec=db,prior=NULL; int cmp; if(rec) do { if((cmp=comparedbkey(key,rec->key))<=0) break; prior = rec; rec = rec->next; } while(rec!=db); idx->it = rec; idx->prior = prior; if(rec&&cmp==0) { copydbdata(rec->data,*data); return 1; } return 0; } int createRec(dbkeytype key, dbdatatype data, indextype idx) /* Precondition: idx->prior points to the record after which the new record should be inserted. (If NULL, the new record is inserted at the head of the list. idx->it points to the record after idx->prior. Action: If the database is not full, adds the record with key key and data data, and returns 1. Otherwise, returns 0. */ { Dbrec rec; rec=(Dbrec)malloc(sizeof(struct dbrec)); if(rec==NULL) return 0; copydbkey(key,rec->key); copydbdata(data,rec->data); if(db==idx.it) /* Note: this is true if db == NULL. */ db = rec; if(idx.prior) { idx.prior->next = rec; rec->next=idx.it; } else rec->next = rec; return 1; } void eachElement(Listptr ptr, void (*fn)(ListData)) { Listptr p=ptr; if(p) do { (*fn)(p->data); p = p->next; } while(p!=ptr); }