I'm taking on a programming challenge for practice and I'm having trouble figuring this one out. It might be due to the time and my current sleepiness, but I want to get this done before bed.
I want to sort the values of each element of an array in ascending order. The trick is not to use a sort() method. Here is what I have so far:
for (int i = 0; i < freq_array.Length; i++)
{
for (int n = 1; n < i; n++)
{
if (freq_array[n] < freq_array[i])
freq_array[i] = freq_array[n];
}
}
for (int x = 0; x < freq_array.Length; x++)
{
lblOutDigits.Text = "";
lblOutDigits.Text += freq_array[x];
}
When testing it out, I just get a '0' in the label. What the freq_array does is hold the frequency of how often certain buttons are clicked. So if I click Button3 5 times, then Button7 3 times, putting them in order I should see 33333777 - even if I clicked 3 and 7 in a random order.