Advertisement
Gheo

Array di strutture Ordinamento

Feb 1st, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.    
  6.     char marca[6];
  7.     int annoimm;
  8. }m;
  9.  
  10. void boolsort(struct  m car[], int);
  11.  
  12. int main(){
  13.     int n, i;
  14.     m *car;
  15.    
  16.     printf("Quante machine ci sono? ");
  17.     scanf("%d", &n);
  18.    
  19.     car=(m*)malloc(n*sizeof(m));
  20.    
  21.     for( i=0; i<n; i++) {
  22.         printf("Machina n.%d :\n", i+1);
  23.         scanf("Marca: %s\n", &car[i].marca );
  24.         scanf("Anno imatricolazione: %d\n", &car[i].annoimm);
  25.     }
  26.    
  27.    
  28. void boolsort(struct m car[], n);
  29.    
  30.     for( i=0; i<n; i++){
  31.         printf("Marca: %s\n", car[i].marca);
  32.         printf("Anno imatriclazione: %d", car[i].annoimm);
  33.        
  34.     }
  35.        
  36.        
  37.     return 0;
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. void boolsort(struct m car[], int b){
  48.     struct m temp, passo=0;
  49.     bool ordinato=false;
  50.     while(passo<b && !ordinato){
  51.         passo=passo+1;
  52.         ordinato=true;
  53.         for(int i=b-1; i>0; i--){
  54.             if( m[i].annoimm<m[i+1].annoimm<){
  55.                 temp=m[i];
  56.                 car[i]=car[i-1];
  57.                 car[i-1]=temp;
  58.                 ordinato=false;
  59.             }
  60.            
  61.         }
  62.        
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement