그래서이 정수 정렬 알고리즘을 수정하여 데이터 요소 (파일 이름)를 목록 상자에서 사전 순으로 작업 할 생각이지만 어떻게 될지 모릅니다.목록 상자와 함께 작동하도록 정렬 알고리즘을 수정 하시겠습니까?
아래의 정렬 알고리즘이 어떻게 작동하는지 이해하고 정수 배열을 사용하여 구현할 수 있습니다. 그러나 listBoxes에 대한 그물에 관련된 예제를 찾을 수없는 것.
public partial class MainWindow : Window
{
Random rand = new Random();
int numOfIntegers = 1000;
int[] array;
public MainWindow()
{
InitializeComponent();
array = new int[numOfIntegers];
}
// sort a vector of type int using exchange sort
public void ExchangeSort(int[] array)
{
int pass, i, n = array.Length;
int temp;
// make n-1 passes through the data
for (pass = 0; pass < n - 1; pass++)
{
// locate least of array[pass] ... array[n - 1]
// at array[pass]
for (i = pass + 1; i < n; i++)
{
if (array[i] < array[pass])
{
temp = array[pass];
array[pass] = array[i];
array[i] = temp;
}
}
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
ExchangeSort(array);
listBox.Items.Clear();
foreach (int i in array)
{
listBox.Items.Add(i);
}
MessageBox.Show("Done");
}
어쩌면의 중복 http://stackoverflow.com/questions/3667088/sorting-a-list-of-items-in-a-list- 상자 – gorgi93
잘 작동하지 않습니다. 이 코드는 올바른 문자로 쓰여졌 기 때문에 – gorgi93
알파벳순으로 숫자를 정렬하고 싶습니까? –