コード例 #1
0
ファイル: MATRIZ.C プロジェクト: teffyhart/inf1301
MTZ_tpCondRet MTZ_DestruirMatriz ( LIS_tppLista Tab )
{
	
	LIS_tppLista Col;
	PLH_tppPilha p;

	while ( Tab != NULL) {
			
			IrFinalLista( Tab );
			Col = (LIS_tppLista) LIS_ObterValor( Tab );
			
		while (Col != NULL) {
				IrFinalLista( Col );
				p = (PLH_tppPilha) LIS_ObterValor( Col );
				PLH_Libera( p );
				LIS_ExcluirElemento( Col );
				IrInicioLista( Col );			
		}

			LIS_ExcluirElemento( Tab );
			IrInicioLista( Tab );
	}		

		free ( Tab );

		return MTZ_CondRetOK;
}
コード例 #2
0
ファイル: graph.c プロジェクト: rbertoche/t2
/* Essa funcao e' responsavel por criar e compor 2 links ligando
 * 2 nos.
 */
enum GRA_Ret linkTwoNodes(Node *node1, Node *node2)
{
	Link *link1, *link2, *link;
	IrInicioLista(node1->links);
	CNT_CONTAR("linkTwoNodes - Inicializacao");
	do{ /* Assertiva: Nao repetir links */
	    CNT_CONTAR("linkTwoNodes - Procurando link igual");
		link = LIS_ObterValor(node1->links);
		if( link && link->n2 == node2 ){
            CNT_CONTAR("linkTwoNodes - Links iguais");
			return GRA_InvalidLink;
		}
	}while (LIS_CondRetOK == LIS_AvancarElementoCorrente (node1->links,1));

    CNT_CONTAR("linkTwoNodes - Compondo Links");
	link1 = (Link*) malloc (sizeof(Link));
	if (!link1){
	CNT_CONTAR("linkTwoNodes - Alocacao de link1 falhou");
		return GRA_MemoryError;
	}
	link2 = (Link*) malloc (sizeof(Link));
	if (!link2){
		/* Muito improvavel de cair aqui num teste
	CNT_CNTAR("linkTwoNodes - Alocacao de link2 falhou"); */
		free (link1);
		return GRA_MemoryError;
	}

	/* Compoe os dois links */
	link1->n1 = node1;
	link1->n2 = node2;
	link1->brother = link2;
	link2->n1 = node2;
	link2->n2 = node1;
	link2->brother = link1;

	IrFinalLista(node1->links);
	IrFinalLista(node2->links);

	/* Tenta inserir cada link em uma lista, limpa se nao der certo */

	CNT_CONTAR("linkTwoNodes - Inserindo link 1 na lista");
	if( LIS_CondRetOK != LIS_InserirElementoApos(node1->links, link1) ){
        CNT_CONTAR("linkTwoNodes - Nao inseriu link 1 na lista");
		return GRA_MemoryError;
    }

    CNT_CONTAR("linkTwoNodes - Inserindo link 2 na lista");
	if( LIS_CondRetOK != LIS_InserirElementoApos(node2->links, link2) ){
        CNT_CONTAR("linkTwoNodes - Nao inseriu link 2 na lista");
		LIS_ExcluirElemento(node1->links);
		return GRA_MemoryError;
	}
#ifdef _DEBUG
	AssertLink(link1);
	AssertLink(link2);
#endif /* _DEBUG */
    CNT_CONTAR("linkTwoNodes - Finalizando");
	return GRA_Ok;
}
コード例 #3
0
/***********************************************************************
*	$FC Função: NPE &Verificar Inserir Carta
***********************************************************************/
NPE_tpCondRet NPE_VerificarInserirCarta(NPE_Coluna destino, Carta carta){
	Carta cartaBase;
	char naipeCarta, naipeCartaBase;
	int valorCarta, valorCartaBase;

	valorCarta = ObterValor(carta);
	naipeCarta = ObterNaipe(carta);

	// Verifica se a carta recebida existe
	if(carta == NULL || valorCarta == -1 || naipeCarta == 'X'){
		return NPE_CondRetCartaNaoExiste;
	}

	// Verifica se a coluna recebida existe
	if(destino == NULL){
		return NPE_CondRetColunaNaoExiste;
	}
	
	// Comparar carta a inserir com carta da "base" da coluna (a de cima do bolo)
	IrFinalLista(destino);
	cartaBase =(Carta)LIS_ObterValor(destino);
	
	valorCartaBase = ObterValor(cartaBase);
	naipeCartaBase = ObterNaipe(cartaBase);

	// Se for NULL, a coluna de naipe está vazia e só recebe um A's
	if(cartaBase == NULL){
		if(ObterValor(carta) != 1){
			return NPE_CondRetNaoPodeInserir;
		}
		else{
			return NPE_CondRetOK;
		}
	}

	// Se os naipes forem diferentes, não pode inserir
	if(naipeCartaBase != naipeCarta){
		return NPE_CondRetNaoPodeInserir;
	}
	// Se os naipes forem iguais, verificar se é seguinte na ordem
	else{
		// Se a carta base já for a última na ordem (K), não pode inserir
		if(valorCartaBase == 13){
			return NPE_CondRetNaoPodeInserir;
		}
		
		if(valorCarta == (valorCartaBase + 1)){
			return NPE_CondRetOK;
		}
		else{
			return NPE_CondRetNaoPodeInserir;
		}
	}
}
コード例 #4
0
ファイル: LISTA.C プロジェクト: Rifeli/t4
//confere numero da quantidade com o numero de movimentos possiveis dentro da lista
LIS_tpCondRet LIS_confereNumero(LIS_tppLista pLista){
	int i, j;
	LIS_tppLista lis;
	IrInicioLista(pLista);

	for(lis = pLista, i = 0; lis->pElemCorr->pProx != NULL; lis->pElemCorr = lis->pElemCorr->pProx, i++);
	IrFinalLista(pLista);

	for(lis = pLista, j = 0; lis->pElemCorr->pAnt != NULL; lis->pElemCorr = lis->pElemCorr->pAnt, j++);
	return ((i > j ? i : j < pLista->numElem) ? LIS_CondRetOK : LIS_CondRetNaoAchou);
}
コード例 #5
0
/***************************************************************************
*
*  Função: PIL  &IR Final Pilha
*  ****/
PIL_tpCondRet PIL_IrFinalPilhaCartas( PIL_tpPilha pPilha ) {
	
	LIS_tpCondRet retorno;

	if (pPilha == NULL)
		return PIL_CondRetPilhaNaoExiste;

	retorno = IrFinalLista( pPilha->cabeca ) ;

	if ( retorno == PIL_CondRetPilhaNaoExiste)
		return PIL_CondRetPilhaNaoExiste;

	return PIL_CondRetOK;
}	/* Fim função: PIL  &Ir Final Pilha Cartas */
コード例 #6
0
ファイル: LISTA.C プロジェクト: Rifeli/t4
LIS_tpCondRet LIS_VerificaSucessorNULL(LIS_tppLista pLista){
	LIS_tppLista lis;

	IrFinalLista(pLista);

	for(lis = pLista; lis->pElemCorr->pAnt != NULL; lis->pElemCorr = lis->pElemCorr->pAnt)
		if(lis->pElemCorr->pAnt->pProx == NULL)
			return LIS_CondRetSucessorNulo;

	if(lis->pElemCorr->pProx == NULL)
		return LIS_CondRetSucessorNulo;

	return LIS_CondRetOK;
}
コード例 #7
0
/***********************************************************************
*	$FC Função: NPE &Exibir Cartas
***********************************************************************/
NPE_tpCondRet NPE_ExibirCarta(NPE_Coluna coluna){
	Carta carta;
	
	// Verifica se a coluna existe
	if(coluna == NULL)
		return NPE_CondRetColunaNaoExiste;

	IrFinalLista(coluna);
	carta = (Carta) LIS_ObterValor(coluna);

	printf("[ %s ]\t", carta);

	return NPE_CondRetOK;
}
コード例 #8
0
ファイル: LISTA.C プロジェクト: Rifeli/t4
LIS_tpCondRet LIS_VerificaLixoSucessor(LIS_tppLista pLista){
	LIS_tppLista lis;

	IrFinalLista(pLista);

	for(lis = pLista; lis->pElemCorr->pAnt != NULL; lis->pElemCorr = lis->pElemCorr->pAnt)
		if(lis->pElemCorr->pAnt->pProx != NULL && lis->pElemCorr->pAnt->pProx != lis->pElemCorr)
			return LIS_CondRetSucessorLixo;

	if(lis->pElemCorr->pProx != NULL && lis->pElemCorr->pProx->pAnt->pProx != lis->pElemCorr->pProx)
		return LIS_CondRetSucessorLixo;

	return LIS_CondRetOK;
}
コード例 #9
0
ファイル: MATRIZ.C プロジェクト: teffyhart/inf1301
void DestruirMatriz ( LIS_tppLista Tab ) {
	
	LIS_tppLista Col;
	PtoTopo* p;

	while ( Tab != NULL) {
			
			IrFinalLista( Tab );
			Col = (LIS_tppLista) LIS_ObterValor( Tab );
			
		while (Col != NULL) {
				IrFinalLista( Col );
				p = (PtoTopo*) LIS_ObterValor( Col );
				libera( p );
				LIS_ExcluirElemento( Col );
				IrInicioLista( Col );			
		}

			LIS_ExcluirElemento( Tab );
			IrInicioLista( Tab );
	}		

		free ( Tab );
}
コード例 #10
0
void DestruirLista(LIS_tppLista plista)
{
	int i, tam;
	void* aux;
	struct tagElemLista * elemAux;
	tam = LIS_ObterTamanho(plista);
	IrFinalLista(plista);
	elemAux = plista->pElemCorr;
	for(i = 0; i < tam; i++)
	{
		free(elemAux->pValor);
		free(elemAux);
		elemAux = plista->pElemCorr->pProx;
	}
	free(plista);
}
コード例 #11
0
/***********************************************************************
*	$FC Função: NPE &Inserir Cartas Em Extra
***********************************************************************/
NPE_tpCondRet NPE_InserirCartaEmNaipe(NPE_Coluna destino, Carta carta){
	LIS_tpCondRet condRet;
	
	if(NPE_VerificarInserirCarta(destino, carta) != NPE_CondRetOK){
		return NPE_CondRetErroAoInserir;
	}
	
	IrFinalLista(destino);
	condRet = LIS_InserirElementoApos(destino, carta);

	if(condRet == LIS_CondRetOK){
		return NPE_CondRetOK;
	}
	else{
		return NPE_CondRetErroAoInserir;
	}
}
コード例 #12
0
/***************************************************************************
*
*  Função: PIL  &Imprimir Pilha Cartas
*  ****/
PIL_tpCondRet PIL_ImprimirPilhaCartas (PIL_tpPilha pPilha) {
	
	CAR_tpCondRet condRetCarta = CAR_CondRetOK;
	LIS_tpCondRet condRetLista;
	int qtd = 0;

	if (pPilha == NULL)
		return PIL_CondRetPilhaNaoExiste;

	printf("\n > ");
	
	PIL_QuantidadeCartas(pPilha,&qtd);
	if (qtd == 0 ) {	
		printf("\n");
		return PIL_CondRetPilhaVazia;
	}

	IrFinalLista(pPilha->cabeca);
	while (qtd) {
	
		CAR_tpCarta carta;
		CAR_tpValor valor;
		CAR_tpNaipe naipe;
		PIL_tpCondRet condRetPilha;

		condRetPilha = PIL_VerCarta(pPilha,&carta);
		if (condRetPilha == PIL_CondRetPilhaVazia)
			return condRetPilha;
	
		
		condRetCarta = CAR_ObterValor(carta,&valor);
		CAR_ObterNaipe(carta,&naipe);

	
		if(condRetCarta == CAR_CondRetCartaInvisivel)
			printf("# ");
		else
			printf(" %s%s ",PegarStringValor(valor),PegarStringNaipe(naipe));

			condRetLista = LIS_AvancarElementoCorrente( pPilha->cabeca , -1 );
	qtd--;
	}
	printf("\n");
	return PIL_CondRetOK;
}	/* Fim função: PIL  &Imprimir Pilha Cartas */
コード例 #13
0
ファイル: graph.c プロジェクト: rbertoche/t2
void delNode (Graph *g, void *n_)
{
	Node * n=n_;

	CNT_CONTAR("delNode - Destruindo lista de links");
	LIS_DestruirLista( n->links );
	if ( g->delData ){
         CNT_CONTAR("delNode - Existe g->delData");
		( *g->delData )( n->data );
    }
#ifdef _DEBUG
	IrFinalLista( g->currentNode );
	free(LIS_ObterValor( g->currentNode ));
	IrInicioLista( g->currentNode );
#endif /* _DEBUG */
    CNT_CONTAR("delNode - Finalizando");
	free (n);
}
コード例 #14
0
ファイル: testlis.c プロジェクト: rbertoche/t2
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
{

    int inxLista  = -1 ,
        numLidos   = -1 ,
        CondRetEsp = -1  ;

    char   StringDado[  DIM_VALOR ] ;

    int ValEsp = -1 ;

    int i ;

    int numElem = -1 ;

    StringDado[ 0 ] = 0 ;

    /* Efetuar reset de teste de lista */

    if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 )
    {

        for( i = 0 ; i < DIM_VT_LISTA ; i++ )
        {
            vtListas[ i ] = NULL ;
        } /* for */

        return TST_CondRetOK ;

    } /* fim ativa: Efetuar reset de teste de lista */

    /* Testar CriarLista */

    else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        vtListas[ inxLista ] =
            LIS_CriarLista( DestruirValor ) ;

        return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
                                         "Erro em ponteiro de nova lista."  ) ;

    } /* fim ativa: Testar CriarLista */

    /* Testar Esvaziar lista lista */

    else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar Esvaziar lista lista */

    /* Testar Destruir lista */

    else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        LIS_DestruirLista( vtListas[ inxLista ] ) ;
        vtListas[ inxLista ] = NULL ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar Destruir lista */

    /* Testar inserir elemento antes */

    else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 )
    {
        struct user *u = (struct user*) malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi" ,
                                      &inxLista , u->nome, u->tel, u->ender , &CondRetEsp ) ;

        if ( ( numLidos != 5 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        lret = LIS_InserirElementoAntes( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret ,
                                "Condicao de retorno errada ao inserir antes."                   ) ;

    } /* fim ativa: Testar inserir elemento antes */

    /* Testar inserir elemento apos */

    else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 )
    {
        struct user *u = (struct user *)malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi",
                                      &inxLista, u->nome, u->tel, u->ender, &CondRetEsp ) ;

        if ( ( numLidos != 5 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        lret = LIS_InserirElementoApos( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret,
                                "Condicao de retorno errada ao inserir antes.") ;
    } /* fim ativa: Testar inserir elemento apos */

    /* Testar excluir simbolo */

    else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "ii" ,
                                      &inxLista , &CondRetEsp ) ;

        if ( ( numLidos != 2 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        return TST_CompararInt( CondRetEsp ,
                                LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                                "Condição de retorno errada ao excluir."   ) ;

    } /* fim ativa: Testar excluir simbolo */

    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste , OBTER_NOME_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->nome,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste, OBTER_TEL_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->tel,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */
    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste , OBTER_ENDER_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->ender,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar ir para o elemento inicial */

    else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" , &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        IrInicioLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar ir para o elemento inicial */

    /* LIS  &Ir para o elemento final */

    else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" , &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        IrFinalLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: LIS  &Ir para o elemento final */

    /* LIS  &Avançar elemento */

    else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                      &CondRetEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        return TST_CompararInt( CondRetEsp ,
                                LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                                "Condicao de retorno errada ao avancar" ) ;

    } /* fim ativa: LIS  &Avançar elemento */

    return TST_CondRetNaoConhec ;

} /* Fim função: TLIS &Testar lista */
コード例 #15
0
int main (void)
{
	int qtdprocessos, met;
	FILE* out = fopen("saida.txt","w");
	int i, j, fail = 0, cnt = 0, tamProntos, tamIO, tamIO2, seg = 0, inxExec, inxIO;
	Processo *aux, *procExec, *procIO, *procRetirado;
	LIS_tppLista listaIO = LIS_CriarLista();
	LIS_tppLista listaProntos = LIS_CriarLista();
	Memory *	mem = (Memory*)malloc(sizeof(Memory));
	FILE* fp = fopen("entrada.txt", "r");
	Processo *vp = (Processo*)malloc(100*sizeof(Processo));
	qtdprocessos = lerEntrada(&fp, vp);
	imprimeVetor(vp, qtdprocessos);
	InicializaMemoria(mem);
	procExec = NULL;
	// Insere os elementos lidos numa lista de prontos
	for(i = 0; i < qtdprocessos; i++)
	{
		LIS_InserirElementoApos(listaProntos, &vp[i]);
		LIS_AvancarElementoCorrente(listaProntos, 1);
		vp[i].segAtual = -1;
		vp[i].naMemoria = 0;
		vp[i].t_exec = 0;
		vp[i].t_io = 0;
	}
	printf("1: First Fit \n");
	printf("2: Best Fit \n");
	printf("3: Worst Fit \n");
	printf("4: Next Fit \n");
	scanf("%d", &met);
EXEC:
	IrInicioLista(listaProntos); // vai pro inicio da lista de prontos
	aux = (Processo*)LIS_ObterValor(listaProntos);
	switch(met)
	{
	case 1:
		firstFit(mem, listaProntos);
		break;
	case 2:
		BestFit(mem, listaProntos);
		break;
	case 3:
		WorstFit(mem, listaProntos);
		break;
	case 4:
		NextFit(mem, listaProntos);
		break;
	default:
		break;
	}
	imprimeMemoria(mem);
	printf("\n Lista de Prontos \n");
	ImprimirLista(listaProntos);
	printf("\n Lista de IO \n");
	ImprimirLista(listaIO);
	/* * * * * * * * * * * * * * * * * * * * * * */
	// executar o processo
	IrInicioLista(listaProntos);
	tamProntos = LIS_ObterTamanho(listaProntos);
	tamIO = LIS_ObterTamanho(listaIO);
	aux =  (Processo*)LIS_ObterValor(listaProntos); // obtem o priemeiro elemento da lista de prontos
	while(tamProntos > 0)
	{
		if(!aux->naMemoria)	// se o processo não esta em memoria
		{
			LIS_AvancarElementoCorrente(listaProntos, 1);
			aux = (Processo*)LIS_ObterValor(listaProntos);
			continue;
		}
		procExec = aux;
		for(i = 0; i < 10; i++) // os 10 clocks de cpu
		{
			ImprimirEstado(&out, listaIO, procExec, mem, tempoTotal);
			clock(1); tempoTotal++;
			inxExec = procExec->t_exec;
			procExec->exec[inxExec]--;
			tamIO = LIS_ObterTamanho(listaIO);
			IrInicioLista(listaIO);
			for(j = 0; j < tamIO; j++) // diminui 1 de IO para todos q estao na lista de I/O
			{
				procIO = (Processo*)LIS_ObterValor(listaIO);
				inxIO = procIO->t_io;
				procIO->io[inxIO]--;
				if(procIO->io[inxIO] == 0) // seu tempo de io acabou
				{
					LIS_ExcluirElemento(listaIO); // retira da lista de io e insere-o na lista de prontos
					IrFinalLista(listaProntos);
					LIS_InserirElementoApos(listaProntos, procIO);
					procIO->t_io++;
				}
				LIS_AvancarElementoCorrente(listaIO, 1);
			}
			tamIO2 = LIS_ObterTamanho(listaIO);
			if(tamIO != tamIO2)
			{
				switch(met)
				{
				case 1:
					firstFit(mem, listaProntos);
					break;
				case 2:
					BestFit(mem, listaProntos);
					break;
				case 3:
					WorstFit(mem, listaProntos);
					break;
				case 4:
					NextFit(mem, listaProntos);
					break;
				default:
					break;
				}
			}
			getNext(listaProntos);
			if(procExec->exec[inxExec] == 0 || i == 9) // se o seu tempo de exec terminou entao retira da memoria
			{
				/* * * * * */	//imprimeMemoria(mem);
				LIS_ExcluirElemento(listaProntos);
				if(procExec->exec[inxExec] == 0) procExec->t_exec++; // se acabou um exec inteiro
				if(procExec->exec[inxExec] == 0 && procExec->t_io < procExec->qtdio) // se o processo terminou um exec e ainda tem io para fazer
				{
					IrFinalLista(listaIO);
					LIS_InserirElementoApos(listaIO, procExec);
				}
				// retira da memoria
				// se o processo ainda tem exec para fazer
				if(procExec->exec[inxExec] > 0)
				{
					IrFinalLista(listaProntos);
					LIS_InserirElementoApos(listaProntos, procExec);
				}
				seg = procExec->segAtual;
				procRetirado = RetiraProcessoMem(mem, seg);
				procRetirado->naMemoria = 0;
				switch(met)
				{
				case 1:
					firstFit(mem, listaProntos);
					break;
				case 2:
					BestFit(mem, listaProntos);
					break;
				case 3:
					WorstFit(mem, listaProntos);
					break;
				case 4:
					NextFit(mem, listaProntos);
					break;
				default:
					break;
				}
				break;
			}
			imprimeMemoria(mem);
			printf("\n Lista de Prontos \n");
			ImprimirLista(listaProntos);
			printf("\n Lista de IO \n");
			ImprimirLista(listaIO);
		} /* final dos 10 clocks*/
		imprimeMemoria(mem);
		printf("\n Lista de Prontos \n");
		ImprimirLista(listaProntos);
		printf("\n Lista de IO \n");
		ImprimirLista(listaIO);
		tamProntos = LIS_ObterTamanho(listaProntos);
		IrInicioLista(listaProntos);
		aux =  (Processo*)LIS_ObterValor(listaProntos);
	}
	tamIO = LIS_ObterTamanho(listaIO);
	while(tamIO > 0) // entao tem IO sobrando e ngm para executar
	{
		IrInicioLista(listaIO);
		clock(1);tempoTotal++;
		for(j = 0; j < tamIO; j++) // diminui 1 de IO para todos q estao na lista de I/O
		{
			procIO = (Processo*)LIS_ObterValor(listaIO);
			inxIO = procIO->t_io;
			procIO->io[inxIO]--;
			if(procIO->io[inxIO] == 0) // seu tempo de io acabou
			{
				LIS_ExcluirElemento(listaIO); // retira da lista de io e insere-o na lista de prontos
				IrFinalLista(listaProntos);
				LIS_InserirElementoApos(listaProntos, procIO);
				procIO->t_io++;
			}
			LIS_AvancarElementoCorrente(listaIO, 1);
		}
		tamIO = LIS_ObterTamanho(listaIO);
		tamProntos = LIS_ObterTamanho(listaProntos);
		imprimeMemoria(mem);
		printf("\n Lista de Prontos \n");
		ImprimirLista(listaProntos);
		printf("\n Lista de IO \n");
		ImprimirLista(listaIO);
		if(tamProntos > 0) // se alguem voltou par a lista de prontos...
			goto EXEC;
	}
	fclose(out);
	free(mem);
	free(vp);
	free(listaProntos);
	free(listaIO);
	return 0;
}
コード例 #16
0
ファイル: TESTLIS.C プロジェクト: Felipe-Visgou/gitproj3
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxLista  = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

	  int CondRetObtido = LIS_CondRetOK;
	  int det, falhasEsperadas, falhasObtidas;

      char   StringDado[  DIM_VALOR ] ;
      char * pDado ;

      int ValEsp = -1 ;

      int i,num ;

      int numElem = -1 ;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de lista */

         if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_LISTA ; i++ )
            {
               vtListas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de lista */

      /* Testar CriarLista */

         else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                       &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            vtListas[ inxLista ] =
                 LIS_CriarLista( DestruirValor ) ;

            return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
               "Erro em ponteiro de nova lista."  ) ;

         } /* fim ativa: Testar CriarLista */

      /* Testar Esvaziar lista lista */

         else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Esvaziar lista lista */

      /* Testar Destruir lista */

         else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_DestruirLista( vtListas[ inxLista ] ) ;
            vtListas[ inxLista ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir lista */

      /* Testar inserir elemento antes */

         else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ;
            if ( pDado == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( pDado , StringDado ) ;


            CondRet = LIS_InserirElementoAntes( vtListas[ inxLista ] , pDado ) ;

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir antes."                   ) ;

         } /* fim ativa: Testar inserir elemento antes */

      /* Testar inserir elemento apos */

         else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ;
            if ( pDado == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( pDado , StringDado ) ;


            CondRet = LIS_InserirElementoApos( vtListas[ inxLista ] , pDado ) ;

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir apos."                   ) ;

         } /* fim ativa: Testar inserir elemento apos */

      /* Testar excluir simbolo */

         else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                  &inxLista , &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar obter valor do elemento corrente */

         else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &ValEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) LIS_ObterValor( vtListas[ inxLista ] ) ;

            if ( ValEsp == 0 )
            {
               return TST_CompararPonteiroNulo( 0 , pDado ,
                         "Valor não deveria existir." ) ;
            } /* if */

            if ( pDado == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado ,
                         "Dado tipo um deveria existir." ) ;
            } /* if */

            return TST_CompararString( StringDado , pDado ,
                         "Valor do elemento errado." ) ;

         } /* fim ativa: Testar obter valor do elemento corrente */

      /* Testar ir para o elemento inicial */

         else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            IrInicioLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar ir para o elemento inicial */

      /* LIS  &Ir para o elemento final */

         else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            IrFinalLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: LIS  &Ir para o elemento final */

      /* LIS  &Avançar elemento */

         else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp , LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                      "Condicao de retorno errada ao avancar" ) ;

         } /* fim ativa: LIS  &Avançar elemento */
		 /* LIS &Testar Obter Tamanho Lista */
		 else if (strcmp ( ComandoTeste , OBTER_TAMANHO_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "iii" ,&inxLista,&ValEsp, &CondRetEsp ) ;

			if ( ( numLidos != 3 )||( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRetObtido = LIS_ObterTamanho( vtListas[ inxLista ], &num );

			CondRet = TST_CompararInt( ValEsp , num ,"Valor do elemento errado, diferente do esperado" ) ;

			if ( CondRet != TST_CondRetOK )
               return CondRet ;

						return TST_CondRetOK;
		 }  /* Fim testar Obter Tamanho */
#ifdef _DEBUG
		 /* Testar Deturpar */
		 else if (strcmp ( ComandoTeste , DETURPA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &det) ;

			if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

			DeturpaLista(vtListas[ inxLista ], det);

			return TST_CondRetOK;
		 }
		 else if (strcmp ( ComandoTeste , VERIFICA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &falhasEsperadas) ;

			if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

			verificaLista(vtListas[ inxLista ], &falhasObtidas);

			CondRet = TST_CompararInt( falhasEsperadas , falhasObtidas ,"Numero de falhas esperadas diferente de obtida" ) ;
			if ( CondRet != TST_CondRetOK )
               return CondRet ;

			return TST_CondRetOK;
		 }
#endif
		 return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS &Testar lista */
コード例 #17
0
ファイル: graph.c プロジェクト: rbertoche/t2
enum GRA_Ret GRA_NewNode (Graph *g, void *data)
{
	Node *n;
#ifdef _DEBUG
	Node *mirror;
	void *offset;
#endif /* _DEBUG */
	LIS_tppLista ln;
    CNT_CONTAR("GRA_NewNode - Inicio");
#ifdef _DEBUG
	AssertGraph(g);
#endif /* _DEBUG */
/* Inicio do bloco de codigo com tratamento de excecao */
	if (!data){
	    CNT_CONTAR("GRA_NewMode - Nao existe data a ser inserida");
		return GRA_NullData;
    }
    CNT_CONTAR("GRA_NewMode - Alocao de no");
	n = (Node *) malloc(sizeof(Node));
	if (!n){
        CNT_CONTAR("GRA_NewMode - Nao alocou no");
		return GRA_MemoryError;
    }

    CNT_CONTAR("GRA_NewMode - Criando Lista");
	ln = LIS_CriarLista(NULL);
	/* Para que ln possa se tornar heterogeneo, uso NULL */
	if (!ln){
        CNT_CONTAR("GRA_NewMode - Nao criou a Lista");
		free (n);
		return GRA_MemoryError;
	}

    CNT_CONTAR("GRA_NewMode - Inserindo elemento apos");
	if (LIS_CondRetOK != LIS_InserirElementoApos( ln, n )){
        CNT_CONTAR("GRA_NewMode - Nao inseriu elemento apos");
		free (n);
		LIS_DestruirLista( ln );
		return GRA_MemoryError;
	}

    CNT_CONTAR("GRA_NewMode - Criando lista de Links");
	n->links = LIS_CriarLista((FDelData) delLink );
	if (!n->links){
        CNT_CONTAR("GRA_NewMode - Nao criou lista de Links");
		free (n);
		LIS_DestruirLista( ln );
		return GRA_MemoryError;
	}

    CNT_CONTAR("GRA_NewMode - Inserindo no final da lista");
	IrFinalLista( g->nodes );
	if ( LIS_CondRetOK != LIS_InserirElementoApos( g->nodes , ln) ){
        CNT_CONTAR("GRA_NewMode - Nao inseriu no final da lista");
		LIS_DestruirLista( n->links );
		free (n);
		LIS_DestruirLista( ln );
		return GRA_MemoryError;
	}
/* Fim do bloco de codigo com tratamento de excecao */

    CNT_CONTAR("GRA_NewMode - Atribuicao, finalizacao");
	n->data = data;
	n->delData = g->delData;
	g->currentNode = ln;
#ifdef _DEBUG
	offset = malloc( 0x200 );
		/* Apenas para que o proximo malloc esteja longe do dado replicado*/
	mirror = (Node *) malloc(sizeof(Node));
	free(offset);
	memcpy(mirror,n, sizeof(Node));
	LIS_InserirElementoApos( ln, mirror );
	IrInicioLista( ln );
	g->nOfNodes++;
	AssertGraph(g);
	AssertNode(n,g);
	CNT_CONTAR("267 GRA_NewNode - Finalizacao");
#endif /* _DEBUG */
	return GRA_Ok;
}