private: // User declarations
int **A,**B,**C,**D, random_Col;
void __fastcall init_Arrays();
void __fastcall destroy_Arrays();
int* __fastcall change_Position(int *tab, int size_Tab);
void __fastcall max_Sort(int *tab, int tab_Size);
void __fastcall min_Sort(int *tab, int tab_Size);
int* __fastcall TForm1::change_Position(int *tab, int size_Tab)
{
int *result_Tab=new int[size_Tab];
int i;
for(i=0;i<size_Tab;i++)
{
result_Tab[i]=tab[(size_Tab-1)-i];
}
return result_Tab;
}
void __fastcall TForm1::max_Sort(int *tab, int tab_Size)
{
int i,j,k;
for(i=1;i<tab_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]<k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
void __fastcall TForm1::min_Sort(int *tab, int tab_Size)
{
int i,j,k;
for(i=1;i<tab_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
void __fastcall TForm1::init_Arrays()
{
int i,j,k,sum;
srand(time(NULL));
A=new int *[5];
B=new int *[5];
C=new int *[5];
D=new int *[5];
for(i=0;i<5;i++)
{
A[i]=new int[10];
B[i]=new int[10];
C[i]=new int[10];
D[i]=new int[10];
}
random_Col=50+rand()%50;
Edit1->Text=IntToStr(random_Col);
i=0;
do
{
do
{
sum=0;
for(j=0;j<10;j++)
{
k=rand()%10+1;
sum+=k;
A[i][j]=k;
}
}while(sum!=random_Col);
++i;
}while(i<5);
for(i=0;i<5;i++)
{
B[i]=change_Position(A[i],10);
}
for(i=0;i<5;i++)
{
for(j=0;j<10;j++)
{
C[i][j]=A[i][j];
D[i][j]=B[i][j];
}
}
for(i=0;i<5;i++)
{
min_Sort(C[i],10);
max_Sort(D[i],10);
}
for(i=0;i<5;i++)
{
for(j=0;j<10;j++)
{
StringGrid1->Cells[j][i]=IntToStr(A[i][j]);
StringGrid2->Cells[j][i]=IntToStr(B[i][j]);
StringGrid3->Cells[j][i]=IntToStr(C[i][j]);
StringGrid4->Cells[j][i]=IntToStr(D[i][j]);
}
}
}
void __fastcall TForm1::destroy_Arrays()
{
int i;
for(i=0;i<5;i++)
{
delete [] D[i];
delete [] C[i];
delete [] B[i];
delete [] A[i];
}
delete [] A;
delete [] B;
delete [] C;
delete [] D;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Arrays();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
destroy_Arrays();
}