예제 #1
0
void Retira(Registro x, Apontador *p)
{  Apontador Aux;
  if (*p == NULL) 
  { printf("Erro : Registro nao esta na arvore\n");
    return;
  }
  if (strcmp(x.Chave, (*p)->Reg.Chave)<0) 
  { Retira(x, &(*p)->Esq); return; }
  if (strcmp(x.Chave, (*p)->Reg.Chave)>0)
  { Retira(x, &(*p)->Dir); return; }
  if ((*p)->Dir == NULL) 
  { Aux = *p;
    *p = (*p)->Esq;
    free(Aux);
    printf("Registro removido com sucesso\n");
    return;
  }
  if ((*p)->Esq != NULL) 
  { Antecessor(*p, &(*p)->Esq);
    return;
  }
  Aux = *p;
  *p = (*p)->Dir;
  free(Aux);
  printf("Registro removido com sucesso\n");
}  
예제 #2
0
파일: lista.c 프로젝트: mateus51/TPs
void FreeLista(Lista *lista) {
	Apontador aux = lista->primeiro;
	while (!ListaVazia(lista)) {
		Retira(lista, aux);
	}
	free(lista->primeiro);
	free(lista);
}
예제 #3
0
void * consumidor (void * args) {
  int i, item;

  for (i = 0; i < 25; i++) {
    item = Retira(i + 1);
    printf("%5d %seh primo\n", item, ehPrimo(item) ? "" : "nao ");
  }

  pthread_exit(NULL);
}
예제 #4
0
파일: lista.c 프로젝트: mateus51/TPs
// Retira o último item da lista
int RetiraUltimo(Lista *lista) {
	if (!ListaVazia(lista)) {
		Apontador aux = lista->primeiro;
		while (aux->prox->prox != NULL) {
			aux = aux->prox;
		}
		return Retira(lista, aux);
	}
	return 0;
}
예제 #5
0
void Retira(Registro x, Apontador *p)
{  Apontador Aux;
  if (*p == NULL) 
  { printf("Erro : Registro nao esta na arvore\n");
    return;
  }
  if (x.Chave < (*p)->Reg.Chave) 
  { Retira(x, &(*p)->Esq); return; }
  if (x.Chave > (*p)->Reg.Chave)
  { Retira(x, &(*p)->Dir); return; }
  if ((*p)->Dir == NULL) 
  { Aux = *p;
    *p = (*p)->Esq;
    free(Aux);
    return;
  }
  if ((*p)->Esq != NULL) 
  { Antecessor(*p, &(*p)->Esq);
    return;
  }
  Aux = *p;
  *p = (*p)->Dir;
  free(Aux);
}  
예제 #6
0
void RetiraAresta(TipoVertice *V1, TipoVertice *V2,TipoPeso *Peso, TipoGrafo *Grafo){
  TipoApontador AuxAnterior, Aux;
  short EncontrouAresta = FALSE;
  TipoItem x;
  AuxAnterior = Grafo->Adj[*V1].Primeiro;
  Aux = Grafo->Adj[*V1].Primeiro->Prox;
  while (Aux != NULL && EncontrouAresta == FALSE)
    { if (*V2 == Aux->Item.Vertice)
      { Retira(AuxAnterior, &Grafo->Adj[*V1], &x);
        Grafo->NumArestas--;
        EncontrouAresta = TRUE;
      }
      AuxAnterior = Aux;
      Aux = Aux->Prox;
    }
}
//=========================FUNÇÃO PRINCIPAL===================================
int main(){

    system("title Controle De Estoque 2011");
    system("color 0f");

    int op,z,d,i,k;
    char resp,c;

    TipoItem item;
    TipoLista Lista;
    ApontadorNo Arvore_cod;

    IniciarLista(&Lista);
    Inicializa(&Arvore_cod);

    i=0;

    do{
        menu();
		scanf("%d",&op);
		system("cls");
		 if(op==1){
            do{
                printf("\t\tGERENCIAMENTO DE ESTOQUE\n\n\tINCLUSAO DE NOVO CADASTRO\n\n");
                fflush(stdin);
                printf("Digite o codigo do produto: ");
                scanf("%d",&item.cod);
                printf("\nDigite o nome do produto: ");
                fflush(stdin);
                gets(&item.nome[i]);
                printf("\nDigite o valor: ");
                fflush(stdin);
                scanf("%f",&item.valor);
                printf("\nDigite o fabricante: ");
                fflush(stdin);
                gets(&item.fabri[i]);
                printf("\nDigite a quantidade: ");
                fflush(stdin);
                scanf("%d",&item.quantidade);
                InserirCelula(&Lista,item);
                printf("\n\tDeseja digita novamente? (S/N).:");
                fflush(stdin);
                Insere(item,&Arvore_cod);
                scanf("%c",&resp);
                system("cls");
            }while(resp=='s');
            system("cls");
        }

        if(op==2){
            printf("\t\t\tESTOQUE\n");
            ImprimeLista(Lista);
            system("pause");
            system("cls");
        }

        if(op==3){
            if(TesteListaVazia(Lista)){
                ImprimeLista(Lista);
                system("pause");
                system("cls");
            }
            else{
                ImprimeLista(Lista);
                do{
                    printf("\n\tQual deseja remover.:");
                    scanf("%d",&k);
                    if(Verificar(k,Lista)==1){
                        fflush(stdin);
                        RetiraL(k,&Lista,&item);
                        fflush(stdin);
                        Retira(item, &Arvore_cod);
                        fflush(stdin);
                        printf("\n\tDeseja Remover novamente? (S/N).:");
                        fflush(stdin);
                        scanf("%c",&resp);
                    }
                }while(resp=='s');
                system("pause");
                system("cls");
            }
        }
        if(op==4){
            if(TesteListaVazia(Lista)){
                ImprimeLista(Lista);
                system("pause");
                system("cls");
            }
            else{
                printf("\t\tOrdenado por valor\n");
                d=Tamanho(Lista);
                QuickSortLista(&Lista,d);
                ImprimeLista(Lista);
                system("pause");
                system("cls");
            }
        }

        if(op==5){
            if(TesteListaVazia(Lista)){
                ImprimeLista(Lista);
                system("pause");
                system("cls");
            }
            else{
                printf("\n\n\n Digite o codigo que deseja encontrar: ");
                scanf("%d", &item.cod);
                fflush(stdin);
                Pesquisa(&item, &Arvore_cod, item.quantidade);
                printf("\n");
                system("pause");
            }
            system("cls");

        }

        if(op==6){

        }

        if(op==7){

        }

        if(op==8){

        }

        if(op==9){

        }

        if(op<1||op>10){
            system("color 4f");
            printf("\tOpcao Invalida\n");
            system("pause");
            system("cls");
            system("color 0f");
        }

         else if(op==10){
            exit(1);
        }

    }while(op>0||op<10);
}
예제 #8
0
파일: otimo.c 프로젝트: enzoroiz/AEDS3-TP2
void EsvaziaLista(TipoLista * Lista){
    TipoItem x;
    while(!Vazia(*Lista)){
        Retira(Lista->Primeiro, Lista, &x);
    }
}
예제 #9
0
int main(int argc, char *argv[])
{
  struct timeval t;
  No *Dicionario;
  Registro x;
  TipoChave vetor[max];
  int i, j, k, n;

  Inicializa(&Dicionario);

  /* Gera uma permutação aleatoria de chaves entre 1 e max */
 
  for (i = 0; i < max; i++)
    vetor[i] = i+1;
  
  //gettimeofday(&t,NULL);
  srand((unsigned int)t.tv_usec);
  Permut(vetor,max-1);

  /* Insere cada chave na arvore e testa sua integridade apos cada insercao */
  for (i = 0; i < max; i++) 
    { x.Chave = vetor[i];
      Insere(x, &Dicionario);
      printf("Inseriu chave: %d\n", x.Chave);
     Testa(Dicionario);
     getchar();
    }
    NotaText(Dicionario);
    
    getchar();

  /* Retira uma chave aleatoriamente e realiza varias pesquisas */
  for (i = 0; i <= max; i++) 
    { k = (int) (10.0*rand()/(RAND_MAX+1.0));
      n = vetor[k];
      x.Chave = n;
      Retira(x, &Dicionario);
      Testa(Dicionario);
      printf("Retirou chave: %ld\n", x.Chave);
      for (j = 0; j < max; j++) 
	{ x.Chave = vetor[(int) (10.0*rand()/(RAND_MAX+1.0))];
          if (x.Chave != n) 
	  { printf("Pesquisando chave: %ld\n", x.Chave);
	    Pesquisa(&x, &Dicionario);
	  }
	}
      x.Chave = n;
      Insere(x, &Dicionario);
      printf("Inseriu chave: %ld\n", x.Chave);
      Testa(Dicionario);
    }

  /* Retira a raiz da arvore ate que ela fique vazia */
  for (i = 0; i < max; i++) 
    { x.Chave = Dicionario->Reg.Chave;
      Retira(x, &Dicionario);
      Testa(Dicionario);
      printf("Retirou chave: %ld\n", x.Chave);
    }
    getchar();
  return 0;
}