N
Nickolas
Ув. программисты, нужна ваша помошь в решении задачи на С++ Builder.
Необходимо создать программу сортировки массивов по возростанию спомошью двух компонентов StingGrid, т.е. на форме присутствуют 2 StingGrid(а) и кнопка. в один StingGrid(1 колонка, 10 строчек) вводятся числа от 0 до ... а в другом выводится результат. код я написал но он не работает(((.
Заранее спасибо! P.S. Я в програмировании не шарю(((((
[codebox]void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int m[10]; //StringGried1
int mres[10];//StringGried2
int max, s, p, b;
m[0]=StrToInt(StringGrid1->Cells[0][0]);
m[1]=StrToInt(StringGrid1->Cells[0][1]);
m[2]=StrToInt(StringGrid1->Cells[0][2]);
m[3]=StrToInt(StringGrid1->Cells[0][3]);
m[4]=StrToInt(StringGrid1->Cells[0][4]); // add to StringGried1
m[5]=StrToInt(StringGrid1->Cells[0][5]);
m[6]=StrToInt(StringGrid1->Cells[0][6]);
m[7]=StrToInt(StringGrid1->Cells[0][7]);
m[8]=StrToInt(StringGrid1->Cells[0][8]);
m[9]=StrToInt(StringGrid1->Cells[0][9]);
max=m[0];
for(int i=0;i<10;i++)
if(m>max) max=m;
mres[0]=max;
s=1;
p=max;
do{ b=-1;
for(int i=0;i<10;i++)
if(m>=b && m<p) b=m;
p=b;
int f=0;
for(int k=0;k<10;k++)
if(m[k] == p) f++;
if(f>1) { for(int i=0;i<10;i++)
if(m==p )
{mres=p; s++; }
}
else {mres=b; s++;}
}while(s<10);
StringGrid2->Cells[0][0]=IntToStr(mres[0]);
StringGrid2->Cells[0][1]=IntToStr(mres[1]);
StringGrid2->Cells[0][2]=IntToStr(mres[2]);
StringGrid2->Cells[0][3]=IntToStr(mres[3]);
StringGrid2->Cells[0][4]=IntToStr(mres[4]);
StringGrid2->Cells[0][5]=IntToStr(mres[5]);
StringGrid2->Cells[0][6]=IntToStr(mres[6]);
StringGrid2->Cells[0][7]=IntToStr(mres[7]);
StringGrid2->Cells[0][8]=IntToStr(mres[8]);
StringGrid2->Cells[0][9]=IntToStr(mres[9]);
getch();
}
[/codebox]
Необходимо создать программу сортировки массивов по возростанию спомошью двух компонентов StingGrid, т.е. на форме присутствуют 2 StingGrid(а) и кнопка. в один StingGrid(1 колонка, 10 строчек) вводятся числа от 0 до ... а в другом выводится результат. код я написал но он не работает(((.
Заранее спасибо! P.S. Я в програмировании не шарю(((((
[codebox]void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int m[10]; //StringGried1
int mres[10];//StringGried2
int max, s, p, b;
m[0]=StrToInt(StringGrid1->Cells[0][0]);
m[1]=StrToInt(StringGrid1->Cells[0][1]);
m[2]=StrToInt(StringGrid1->Cells[0][2]);
m[3]=StrToInt(StringGrid1->Cells[0][3]);
m[4]=StrToInt(StringGrid1->Cells[0][4]); // add to StringGried1
m[5]=StrToInt(StringGrid1->Cells[0][5]);
m[6]=StrToInt(StringGrid1->Cells[0][6]);
m[7]=StrToInt(StringGrid1->Cells[0][7]);
m[8]=StrToInt(StringGrid1->Cells[0][8]);
m[9]=StrToInt(StringGrid1->Cells[0][9]);
max=m[0];
for(int i=0;i<10;i++)
if(m>max) max=m;
mres[0]=max;
s=1;
p=max;
do{ b=-1;
for(int i=0;i<10;i++)
if(m>=b && m<p) b=m;
p=b;
int f=0;
for(int k=0;k<10;k++)
if(m[k] == p) f++;
if(f>1) { for(int i=0;i<10;i++)
if(m==p )
{mres
}
else {mres
}while(s<10);
StringGrid2->Cells[0][0]=IntToStr(mres[0]);
StringGrid2->Cells[0][1]=IntToStr(mres[1]);
StringGrid2->Cells[0][2]=IntToStr(mres[2]);
StringGrid2->Cells[0][3]=IntToStr(mres[3]);
StringGrid2->Cells[0][4]=IntToStr(mres[4]);
StringGrid2->Cells[0][5]=IntToStr(mres[5]);
StringGrid2->Cells[0][6]=IntToStr(mres[6]);
StringGrid2->Cells[0][7]=IntToStr(mres[7]);
StringGrid2->Cells[0][8]=IntToStr(mres[8]);
StringGrid2->Cells[0][9]=IntToStr(mres[9]);
getch();
}
[/codebox]