먼저
Form1에다가 TstringGrid를 만들고 숫자를 적을 수 있도록 editing을 true로 했습니다.
기본적으로
┌─┐<--StringGrid1
│ 1│
│ 4│ ┌───────┐<--Button1
│ 5│ │ 오름차순정렬│
│ 3│ └───────┘
│ 2│
└─┘
라고 적고, 오름차순정렬 버튼을 누르면
숫자들이
┌─┐
│ 1│
│ 2│ ┌───────┐
│ 3│ │ 오름차순정렬│
│ 4│ └───────┘
│ 5│
└─┘
이렇게 정렬이 되도록 하려고 합니다.
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
참조한 소스내용
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=429
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
void strQSort( TStringGrid *gr, int left, int right )
{
int i, j;
AnsiString sPx, sPw;
do
{
sPx = gr->Cells[0][(left+right)/2];
i = left; //1 <- 이것들 실험하다가 실수 했네요.... 다시 수정했습니다.
j = right; //RowCount-1; 이것 그대로 나두면 처음 1번 외에 다운 됩니다.
do
{
while( gr->Cells[0][i].AnsiCompare( sPx ) < 0 ) i++;
while( gr->Cells[0][j].AnsiCompare( sPx ) > 0 ) j--;
if( i>j ) break;
sPw = gr->Cells[0][i]; //컬럼은 3개 입니다.
gr->Cells[0][i] = gr->Cells[0][j]; // 맨 앞 칼럼이 정렬로 바뀌니까? 다른 칼럼도 같이 이동
gr->Cells[0][j] = sPw;
sPw = gr->Cells[1][i];
gr->Cells[1][i] = gr->Cells[1][j];
gr->Cells[1][j] = sPw;
sPw = gr->Cells[2][i];
gr->Cells[2][i] = gr->Cells[2][j];
gr->Cells[2][j] = sPw;
} while( ++i <= --j );
if( j - left < right - i )
{
if( left < j ) strQSort( gr, left, j );
left = i; j = right;
}
else
{
if( i < right ) strQSort( gr, i, right );
right = j; i = left;
}
} while( left < right );
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
strQSort( sgTheater, 1, sgTheater->RowCount-1 );
// TStringGrid *sgTheater 입니다.
}
//---------------------------------------------------------------------------
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
여기에서
1> TstringGrid에 숫자를 적으면 어떻게 컴퓨터가 저장을 하고 있으며...
(editbox의 경우는 Edit1->Text에 저장하고 있듯이...)
2> 위의 소스가 맞는지 (맞다면 h파일이나 기본 cpp가 아닌곳에 무엇을 정의 해줘야하는지 알려주시면 감사하겠습니다.)
혹시 제가 하려고하는 것과 비슷한 샘플을 가지고 계시거나, 보셨다면 리플로 적어주세요.
많은 도움 부탁드립니다.