1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include "stdafx.h"
#include <iostream>
int main(int argc, char* argv[])
{
const int N=9;
int tab[N]={2,1,3,1,2,1,3,2,3};
int med[N];
int passage[3];
int ref=0;
int comp=1;
int stc=0;
for( i=0;i<N-2;i++)
{
for(int j=i; j<3+i; j++)
{
passage[j]=tab[j]; //tableau ou je stocke les valeurs à traiter
std::cout<<passage[j];
}
std::cout<<std::endl;
while(ref<=2)
{
while(comp<3)
{
if(passage[comp]<passage[ref])
{
stc=passage[ref];
passage[ref]=passage[comp];
passage[comp]=stc;
}
else
{
comp=comp+1;
}
}
ref = ref+1;
comp = ref+1;
}
med[i]=passage[(3-1)/2+1];
med[N-2]=tab[N-2];
med[N-1]=tab[N-1];
med[N]=tab[N];
}
for(i=0;i<N;i++)
{
std::cout<<med[i];
}
return 0;
} |
Partager