Exemplo n.º 1
0
/* Initializes a search table.
 * Returns pointer to initialized table.
 *
 */
SEARCH_TABLE *STnew(
 size_t nrFastList, /* nr. of elements in fast list
                          * these are indexed by their position.
                          * if > 0 then specify ReturnId.
                          */
 size_t recSize,  /* size of a record */
 RETURN_ID ReturnId, /* pointer to function that
                          * returns the id, can be NULL 
                          * if nrFastList is 0 or
                          * STinsertOrFind is never used
                          */
 INIT_REC InitRec,    /* pointer to function to
                       * initialize records in the
                       * fastlist or in the InsertOrFind call,
                       * can be NULL if nrFastList is 0 or
                       * STinsertOrFind is never used
                       */
 QSORT_CMP cmp)         /* pointer to compare function */
{
 SEARCH_TABLE *t;
 PRECOND(cmp != NULL);
#ifdef DEBUG
 if (nrFastList > 0)
  PRECOND(nrFastList > 0 && ReturnId != NULL && InitRec != NULL);
#endif 
 t = (SEARCH_TABLE *)ChkMalloc(sizeof(SEARCH_TABLE));
 if(t == NULL)
  return NULL;  /* memory allocation failed */
 t->nrFastList = nrFastList; 
 t->recSize = recSize; 
 /* init slowList here so STfree works in this function */
 t->slowList = NULL;  /* slowlist = empty */
 t->nrSlowList = 0;  /* nr. elements in slow list */
 t->ReturnId = ReturnId;
 t->cmp = cmp;   /* for binary search */
 t->InitRec = InitRec;
 if(nrFastList != 0)
 {
  size_t i;
  char *r;
  t->fastList = ChkMalloc(nrFastList * recSize);
  if(t->fastList == NULL)
  {
   STfree(t);
   return NULL;
  }
  r = t->fastList;
  for ( i = 0 ; i  < nrFastList; i++)
  { 
   InitRec((void *)r,(int)i);
   r += recSize;
  } 
 }
 else
  t->fastList = NULL;
# ifdef DEBUG_DEVELOP
  nrSearchTables++;
# endif
 return t;
}
Exemplo n.º 2
0
void STfreeAction(
 SEARCH_TABLE *t, /* table to deallocate */
 ACTION_REC   action) /* */
{

 if (t!=NULL)
 {
  STforAll(t, action);
  STfree(t);
 }
}
Exemplo n.º 3
0
int main(){

    int valor;
    long int refe, refb, refc, ref;
    char command[CMD_LENGTH] = "";

    STinit(&clientes);
    cheques = QUEUEinit(10);
    scanf("%s",command);

    while(strcmp(command,"sair")){

        if(!strcmp(command,"cheque")){
            scanf("%d%ld%ld%ld",&valor,&refe,&refb,&refc);
            adiciona_cheque(valor,refe,refb,refc);
        }

        else if(!strcmp(command,"processa"))
            processa_cheque();

        else if(!strcmp(command,"processaR")){
            scanf("%ld",&refc);
            processa_cheque_ref(refc);
        }

        else if(!strcmp(command,"infocheque")){
            scanf("%ld",&ref);
            info_cheque(ref);
        }

        else if(!strcmp(command,"infocliente")){
            scanf("%ld",&ref);
            info_cliente(ref);
        }

        else if(!strcmp(command,"info"))
            STsort(clientes, infoCliente);

        else
            printf("ERROR: Unknown command\n");

        scanf("%s",command);
        
    }

    clientes_activos();
    cheques_por_processar();
    STfree(&clientes);

    return 0;
}