Facebook
From Fiery Zebra, 2 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 106
  1. #include <stdio.h>
  2.  
  3. void imprime_indireto (int **A_indireto, int n) {
  4.     for (int i=0; i<n; i++)
  5.         printf ("%d ", **(A_indireto+i));
  6. }
  7.  
  8. void ordenarVetor(int n, int *A_indireto[n]){
  9.     int i = 0, j = 0, *aux = NULL;
  10.     for(i = 0; i < n; i++){
  11.         for(j = i+1; j < n; j++){
  12.             if(*A_indireto[i] > *A_indireto[j]){
  13.                 aux = A_indireto[i];
  14.                 A_indireto[i] = A_indireto[j];
  15.                 A_indireto[j] = aux;
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21. int main(){
  22.     int n, i;
  23.    
  24.     scanf("%i", &n);
  25.     int A[n];
  26.     int *A_indireto[n];
  27.    
  28.     for(i = 0; i < n; i++){
  29.         scanf("%i", &A[i]);
  30.         A_indireto[i] = &A[i];
  31.     }
  32.    
  33.    
  34.     ordenarVetor(n, A_indireto);
  35.     imprime_indireto(A_indireto, n);
  36.     printf("\n");
  37.     for(i = 0; i < n; i++){
  38.         printf("%i ", A[i]);
  39.     }
  40.  
  41. }