I'm creating a label array where the Label EntryLabel creates 12 Random numbers in ascending order and an EntryText where 3 numbers are added by the user, on the click of the button the 12 numbers generated plus the 3 typed form an array of LabelResults of 15 numbers, so far Perfect,
the question is: I'm not managing to order after the ResultLabel, someone would have an idea to help me:
I'm using a BubbleSort method but I don't get a result,
where am I going wrong?
part of the code follows:
the question is: I'm not managing to order after the ResultLabel, someone would have an idea to help me:
I'm using a BubbleSort method but I don't get a result,
where am I going wrong?
part of the code follows:
C#:
Label[] EntradaLabel = new Label[12];
Label[] EntradaText = new Label[3];
Label[] ResultadoLabel = new Label[15];
public frmTesteEnum()
{
InitializeComponent();
GeraControles();
gerador();
}
private void GeraControles()
{
int i, esquerda = 50, topo = 30;
for (i = 0; i < 12; i++)
{
EntradaLabel[i] = new Label();
EntradaLabel[i].Name = "" + i;
EntradaLabel[i].Text = EntradaLabel[i].Name;
EntradaLabel[i].Left = esquerda; //Defina a posição do controle no formulário
EntradaLabel[i].Top = topo;
EntradaLabel[i].Font = new Font("", 15, FontStyle.Bold);
EntradaLabel[i].BorderStyle = BorderStyle.Fixed3D;
this.Controls.Add(EntradaLabel[i]); // Adicione os controle ao formulário
topo += (EntradaLabel[i].Height + 5);
}
for (i = 0; i < 3; i++)
{
EntradaText[i] = new Label();
EntradaText[i].Name = " " + i;
EntradaText[i].Text = EntradaText[i].Name;
EntradaText[i].Left = esquerda;
EntradaText[i].Top = topo;
EntradaText[i].Font = new Font("", 15, FontStyle.Bold);
EntradaText[i].BorderStyle = BorderStyle.Fixed3D;
this.Controls.Add(EntradaText[i]);
topo += EntradaText[i].Height + 5;
}
esquerda = 200;
topo = 30;
for (i = 0; i < 15; i++)
{
ResultadoLabel[i] = new Label();
ResultadoLabel[i].Name = "label" + i;
ResultadoLabel[i].Text = ResultadoLabel[i].Name;
ResultadoLabel[i].Left = esquerda;
ResultadoLabel[i].Top = topo;
ResultadoLabel[i].Font = new Font("", 15, FontStyle.Bold);
ResultadoLabel[i].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(ResultadoLabel[i]);
topo += (ResultadoLabel[i].Height + 5);
}
}
private void MostraResultado()
{
int i, ii = 0;
for (i = 0; i < 12; i++)
ResultadoLabel[i].Text = EntradaLabel[i].Text;
for (; i < 15; i++)
ResultadoLabel[i].Text = EntradaText[ii++].Text;
}
private void btnGerarNumeros_Click(object sender, EventArgs e)
{
//Array ResultadoLabel = Array.CreateInstance(typeof(int), new int[25]);
//int[] ResultadoLabel = new int[25];
if (EntradaText[0].Text == "" | EntradaText[1].Text == "" | EntradaText[2].Text == "")
{
MessageBox.Show("Por favor, escolha os tres numeros Fixos", "Adevertencia", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
MostraResultado();
}
}
private void gerador()
{
Aleatorios ale = new Aleatorios();
int[] numerosSorteados = ale.GeradorNaoRepetidoss(12, 1, 25);
Array.Sort(numerosSorteados);
Control[] controles = EntradaLabel;
for (int i = 0; i < controles.Length; i++)
{
int valor = numerosSorteados[i];
controles[i].Text = valor + "";
}
}
// criando o método bubblesort
public void bubblesort(int[] y)
{
for (int i = 1; i < y.Length; i++)
for (int j = 0; j < y.Length - 1; j++)
if (y[j] > y[j + 1])
troca(y, j);
}
// algoritmo de troca de valores de variáveis:
public void troca(int[] g, int primeiro)
{
int aux;
aux = g[primeiro];
g[primeiro] = g[primeiro + 1];
g[primeiro + 1] = aux;
}