Ver Mensaje Individual
  #10  
Antiguo 08-03-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Jusar.

Primero que nada felicito a Hector por su poder de interpretación

Entonces, más o menos sería:
Código:
const MAXFIL = 2;
const MAXCOL = MAXFIL+1;

int Matriz[MAXFIL][MAXCOL];

void Cargar(int (*m)[MAXCOL])
{
  for(int f=0; f < MAXFIL; f++)
   for(int c=0; c < MAXCOL; c++) {
      m[c][f] = c+1;
      m[c][f+1] = c+2;
    }
}

void Mezclar(int (*m)[MAXCOL])
{
TSmallPoint a,b;
int tmp;
  for (int i=0; i < 100; i++) {
    a.x = random(MAXCOL);
    b.x = random(MAXCOL);
    a.y = random(MAXFIL);
    b.y = random(MAXFIL);
    tmp = Matriz[a.x][a.y];
    m[a.x][a.y] = m[b.x][b.y];
    m[b.x][b.y] = tmp;
  }
}

void Mostrar(TMemo *M)
{
AnsiString s;
  for(int f=0; f < MAXFIL; f++) {
    s = "";
    for(int c=0; c < MAXCOL; c++)
      s = s + IntToStr(Matriz[c][f])+ ' ';
    M->Lines->Add(s);
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
 Cargar(Matriz);
 Memo1->Clear();
 Memo1->ScrollBars = ssVertical;
 Memo1->Lines->Add("Estado inicial");
 Memo1->Lines->Add("-----------------");
 Mostrar(Memo1);

}

void __fastcall TForm1::btnShowClick(TObject *Sender)
{
 Mezclar(Matriz);
 Memo1->Lines->Add("-----------------");
 Mostrar(Memo1);
}
Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita