コード例 #1
0
void Pesquisa(TipoItem *x, ApontadorNo *p, int quantidade) {
  int i;
  if (*p == NULL) {
    system("color 4f");
  	printf("\n\n\t Erro: Registro nao encontrado! \n");
  	system("pause");
    system("cls");
  	system("color 0f");
    return;
  }

  if (x->cod < (*p)->Reg.cod) {
  	Pesquisa(x, &(*p)->Esq, quantidade);
    return;
  }

  if (x->cod > (*p)->Reg.cod)
	Pesquisa(x, &(*p)->Dir, quantidade);
  else
    *x = (*p)->Reg;

    if( x->cod == (*p)->Reg.cod){
        printf("\n\n\t Registro Encontrado: \n");
        printf("\n Codigo do produto: %d\t\t",x->cod);
        printf("\n Nome: %s",x->nome);
        printf("\n Valor: %.2f ",x->valor);
        printf("\tFabricante: %s\n",x->fabri);
        printf("\n Estoque: %d ",x->quantidade);
        return;
    }
}
コード例 #2
0
void Pesquisa(Registro *x, Apontador *p)
{ if (*p == NULL) 
  { printf("Erro : Registro nao esta presente na arvore\n");
    return;
  }
  if (strcmp(x->Chave, (*p)->Reg.Chave)<0) 
  { Pesquisa(x, &(*p)->Esq);
    return;
  }
  if (strcmp(x->Chave, (*p)->Reg.Chave)>0)
  Pesquisa(x, &(*p)->Dir);
  else
    *x = (*p)->Reg;
} 
コード例 #3
0
ファイル: projetoc.cpp プロジェクト: ssbreno/Encadeada
void filaencadeada(int op)
{
	int ele;
	
	switch(op){
		case 0:
			exit(1);
			break;
		case 1:
		    Fvazia();
			break;
		case 2:
	 	    Imprime();
			break;

		case 3:
			printf("Novo Elemento:\n");
		    scanf("%d",&ele);	
			Insere(ele);	
			break;
		case 4:
			printf("Buscar Elemento:\n");
		    scanf("%d",&ele);	
			Pesquisa(ele);			
			break;
		case 5:
		 	Remove();
		 	Imprime();	
			break;

		default:
			printf("Comando invalido\n\n");
	}
	
}
コード例 #4
0
ファイル: hash.c プロジェクト: paulob/compilex
int Insere(TipoItem x, TipoPeso p, TipoTabela T)
{
  if (Pesquisa(x.Variavel, p, T) == NULL){
    Ins(x, &T[h(x.Variavel, p)]);
	return 1;
     }
      else
        return 0;
}
コード例 #5
0
void Pesquisa(TipoRegistro *x, TipoApontador *Ap) {
	int i;
	TipoApontador Pag;
	Pag = *Ap;
	if ((*Ap)->Pt == Interna) {
		i = 1;
		while (i < Pag->UU.U0.ni && x->Chave > Pag->UU.U0.ri[i - 1])
			i++;
		if (x->Chave < Pag->UU.U0.ri[i - 1]) Pesquisa(x, &Pag->UU.U0.pi[i - 1]);
		else Pesquisa(x, &Pag->UU.U0.pi[i]);
		return;
	}
	i = 1;
	while (i < Pag->UU.U1.ne && x->Chave > Pag->UU.U1.re[i - 1].Chave)
		i++;
	if (x->Chave == Pag->UU.U1.re[i - 1].Chave)
		*x = Pag->UU.U1.re[i - 1];
	else
		printf("TipoRegistro nao esta presente na arvore\n");
}
コード例 #6
0
//=========================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);
}
コード例 #7
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;
}