Professional Documents
Culture Documents
Clase Cordenamiento
Clase Cordenamiento
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ordenamiento
{
internal class cOrdenamiento
{
// Atributos
private int[] aarreglo;
private int an;
// Propiedades
public int[] Arreglo {get => aarreglo; set => aarreglo = value; }
// Metodos
public void swap(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
public int[] OrdenamientoInsercion()
{
return Arreglo;
}
public int[] OrdenamientoSeleccion()
{
int min_pos;
for (int i = 0; i < N; i++)
{
min_pos = i;
for (int x = i + 1; x < N; x++)
{
if (Arreglo[x] < Arreglo[min_pos])
{
min_pos = x;
}
}
if (min_pos != i)
{
swap(ref Arreglo[i], ref Arreglo[min_pos]);
}
}
return Arreglo;
}
Main Program
using System;
using System.Diagnostics;
namespace Ordenamiento
{
class Program
{
static void Main(string[] args)
{
int n = 19;
int[] arrB = new int[n];
int[] arrI = new int[n];
int[] arrS = new int[n];
Random rand = new Random();
for (int i = 0; i < n; i++)
{
int num = rand.Next(0, 100);
arrB[i] = num;
arrI[i] = num;
arrS[i] = num;
}
cOrdenamiento ordB = new cOrdenamiento(arrB);
cOrdenamiento ordS = new cOrdenamiento(arrS);
cOrdenamiento ordI = new cOrdenamiento(arrI);
int[] resB = ordB.OrdenamientoBurbuja();
int[] resI = ordI.OrdenamientoInsercion();
int[] resS = ordS.OrdenamientoSeleccion();
Console.WriteLine("\n Burbuja ");
for (int i = 0; i < n; i++)
{
Console.Write(" " + resB[i]);
}
Console.WriteLine("\n Seleccion ");
for (int i = 0; i < n; i++)
{
Console.Write(" " + resS[i]);
}
Console.WriteLine("\n Insercion ");
for (int i = 0; i < n; i++)
{
Console.Write(" " + resI[i]);
}
// Inicializamos el reloj
Stopwatch stopwatch = new Stopwatch();
int[] ln = { 10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000,
2000, 3000, 5000, 10000, 20000, 50000, 100000 };
foreach (int k in ln)
{
stopwatch.Start();
Console.WriteLine("");
// pon aqu tu codigo
Console.WriteLine(ordB.OrdenamientoBurbuja());
stopwatch.Stop();
Console.WriteLine("\nEl tiempo transcurrido con el ordenamiento
burbuja es {0} ms", stopwatch.ElapsedMilliseconds / 1000.0);
}
foreach (int h in ln)
{
stopwatch.Start();
Console.WriteLine("");
// pon aqu tu codigo
Console.WriteLine(ordI.OrdenamientoInsercion());
stopwatch.Stop();
Console.WriteLine("\nEl tiempo transcurrido con el ordenamiento
insercion es {0} ms", stopwatch.ElapsedMilliseconds / 1000.0);
}
foreach (int h in ln)
{
stopwatch.Start();
Console.WriteLine("");
// pon aqu tu codigo
Console.WriteLine(ordS.OrdenamientoSeleccion());
stopwatch.Stop();
Console.WriteLine("\nEl tiempo transcurrido con el ordenamiento
seleccion es {0} ms", stopwatch.ElapsedMilliseconds / 1000.0);
}
}
}
}