| 12
 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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 
 | #include <cstdlib>
#include <iostream>
 
using namespace std;
// Prototypes
void suivant(int a, int b, int &c, int &d);
void TriCirculaire(int tab[5][5]);
void TriLigne(int tab[5][5]);
void Afficher(int tab[5][5]);
void Remplir(int tab[5][5]);
 
int main(int argc, char *argv[])
{
    // Déclaration des variables 
    int tab[5][5];
 
    // RAZ nombres aléatoires
    srand(time(NULL));
 
    // Tableau non ordonné
    Remplir(tab);
    cout << "Tableau non ordonne :" << endl;
    Afficher(tab);
    // Tableau ordonné en ligne
    TriLigne(tab);
    cout << "Tableau ordonne en ligne :" << endl;
    Afficher(tab);
    // Tableau ordonné de façon circulaire
    TriCirculaire(tab);
    cout << "Tableau ordonne en circulaire :" << endl;
    Afficher(tab);
 
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
 
// REMPLIR
void Remplir(int tab[5][5])
{
     for (int i = 0 ; i < 5 ; i++)
     {
         for (int j = 0 ; j < 5 ; j++)
         {
             tab[i][j] = rand() % 100+1;
         }
     }
}
 
// AFFICHER    
void Afficher(int tab[5][5])
{
     for (int i = 0 ; i < 5 ; i++)
     {
         for (int j = 0 ; j < 5 ; j++)
         {
             cout << tab[i][j] << "  ";
         }
     cout << endl;
     }
     cout << endl;
}
 
// TRI EN LIGNE
void TriLigne(int tab[5][5])
{
     int temp;
     for (int i = 0 ; i < 5 ; i++)
     {
         for (int j = 0 ; j < 5 ; j++)
         {
             for (int next = j+1 ; next < 5 ; next++)
             {
                 if(tab[i][j] > tab[i][next])
                 {
                     temp = tab[i][j];
                     tab[i][j] = tab[i][next];
                     tab[i][next] = temp;
                 }
             }
         }
     }
}
 
// SUIVANT
void suivant(int ligne, int col, int &nLigne, int &nCol)
{
     if(col == 0)
     {
         if(ligne > 1)
         {
             nLigne = ligne - 1;
             nCol = col;
         }
     }
     if(ligne == 4)
     {
         if(col > 0)
         {
             nLigne = ligne;
             nCol = col -1;
         }
         else // col == 0
         {
             nLigne = ligne - 1;
             nCol = col;
         }
     }  // Fin de la ligne 4
 
     if(col == 4)
     {
         if(ligne < 4)
         {
             nLigne = ligne + 1;
             nCol = col;
         }
         else // col == 4
         {
             nLigne = ligne;
             nCol = col - 1;
         }
     }  // Fin de la colonne 4        
 
     if(ligne == 0)
     {
         if(col < 4)
         {
             nLigne = ligne;
             nCol = col + 1;
         }
         else // col == 4
         {
             nLigne = ligne + 1;
             nCol = col;
         }
     } //Fin de ligne 0        
} 
 
// TRI CIRCULAIRE
void TriCirculaire(int tab[5][5])
{
 
     int xReference = 0 , YReference = 0 , Nextx = 0 , Nexty = 0;
     bool Fini = false;
     while(!Fini)      // Boucle qui va de l'element courant jusqu'à tous ses suivants
     {                 
         bool ParcoursFini = false;
         while(!ParcoursFini)
         {
                 // A COMPLETER
         ParcoursFini = true;                                 
         }
 
         suivant(xReference,YReference,Nextx,Nexty);
         cout << "[" << xReference << "," << YReference << "]" << "[" << Nextx << "," << Nexty << "]" << "\n";
         if ( (Nextx == 1)&&(Nexty == 0) )
         {
             Fini = true;
         }
         xReference = Nextx;
         YReference = Nexty;   
     }
} | 
Partager