Ordinamento

#include <stdio.h>
int ar[10];
int i,j;
int swc;
int comodo=0;
void scambio(int i,int j){
     int comodo;
     comodo=ar[i];
     ar[i]=ar[j];
     ar[j]=comodo;
}
void carica(){
     ar[0]=27;
     ar[1]=1;
     ar[2]=45;
     ar[3]=7;
     ar[4]=-10;
     ar[5]=67;
     ar[6]=-45;
     ar[7]=56;
     ar[8]=3;
     ar[9]=100;
}
void stampa(){
     for(i=0;i<10;i++){
                       printf("%d\n",ar[i]);
                       }
     }
void ordina1(){
     do{
        swc=0;
        for(i=0;i<9;i++){  
                            j=i+1;
                            if(ar[i]>ar[j]){
                                            scambio(i,j);
                                            swc=1;
                                         }
                            }            
        }              
     while(swc==1);
}         
void ordina2(){
     for(i=0;i<8;i++){
                for(j=i+1;j<9;j++){
                if(ar[i]>ar[j]){
                             comodo=ar[i];
                             ar[i]=ar[j];
                             ar[j]=comodo;
                                }
                }
}
for(i=0;i<10;i++){
                  printf("%d\n",ar[i]);
}
}                               
int main()
{
carica();
stampa();
ordina1();
printf("----------------\n");
stampa();
printf("----------------\n");
ordina2();

}

Commenti