1 2 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
|
#pragma endregion
Pen^ blackPen;
Graphics^ g1;
Graphics^ g2;
Brush^ blackBrush;
Brush^ redBrush;
System::Drawing::Font^ arial6Font;
private: System::Void btnSort_Click(System::Object^ sender, System::EventArgs^ e) {
int data[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int n = 20;
int i, j;
int smallIndex;
//DrawArray(data, n); //draw unsorted array in panel1
//insert selection sort code
for (i = 0; i < n-1; i++)
{
//find the smallest unsorted value
//set location of smallIndex to 1
smallIndex = i;
//compare all elements from data[i+1] to data [n-1]
for (j = i+1; j < n; j++)
if (data[j] > data[smallIndex]) smallIndex = j;
//swap the value in data[smallindex] with data[i]
Swap(data[i], data[smallIndex]);
}
DrawArray(data, n); // draw sorted array in panel2
}
|