所以我试图找出修改这个整数排序算法以在列表框中按字母顺序处理数据元素(文件名),但不知道如何?
我了解下面的排序算法是如何工作的,并且可以使用整数数组来实现它。但是,对于 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");
}