Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void preenche(int *vet[], int tam){
- int i;
- for(i=0; i<tam; i++){
- printf("Vetor[%i]: ", i);
- scanf("%d", (vet+i));
- }
- }
- void ordena(int *vet[], int tam){
- int i, j, aux;
- for(i=0; i<tam; i++){
- for(j=0; j<tam; j++){
- if(*(vet+j)>*(vet+i)){
- aux=*(vet+i);
- *(vet+i) = *(vet+j);
- *(vet+j) = aux;
- }
- }
- }
- }
- void intercalacao(int *vet1[], int *vet2[], int *vet3[], int tam){
- int i, j, a=0, b=0;
- for(i=0; i<tam*2; i++){
- int valorVet1 = *(vet1+a);
- int valorvet2 = *(vet2+b);
- if(valorVet1 < valorvet2){
- *(vet3+i)=valorVet1;
- a++;
- // deslocar o a;
- // atribuir valorget1 para vet3
- }
- else if(valorvet2<valorVet1){
- *(vet3+i)=valorvet2;
- b++;
- }
- }
- }
- void imprime(int *vet[], int tam){
- int i;
- for(i=0; i<tam; i++){
- printf("%d\t", *(vet+i));
- }
- }
- int main()
- {
- int tam;
- printf("Digite o tamanho dos vetores: ");
- scanf("%d", &tam);
- int *vet1, *vet2, *vet3;
- vet1=malloc(tam*sizeof(int));
- vet2=malloc(tam*sizeof(int));
- vet3=malloc((2*tam)*sizeof(int));
- printf("Vetor A: \n");
- preenche(vet1, tam);
- printf("\nVetor B: \n");
- preenche(vet2, tam);
- ordena(vet1, tam);
- ordena(vet2, tam);
- intercalacao(vet1, vet2, vet3, tam);
- imprime(vet3,2*tam);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement