Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1. OBJETIVOS
Implementar aplicaciones con métodos de ordenamiento: burbuja, inserción directa,
selección, Shell y quicksort.
2. EQUIPOS Y MATERIALES
Visual Studio
IMPLEMENTACIÓN EN CONSOLA
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PruebaVector
{
class PruebaVector
{
private int[] vector;
{
int auxili;
FUNDAMENTOS DE PROGRAMACION
int j;
for (int i = 0; i < vector.Length; i++)
{
auxili = vector[i];
j = i - 1;
while (j >= 0 && vector[j] > auxili)
{
vector[j + 1] = vector[j];
j--;
}
vector[j + 1] = auxili;
}
}
FUNDAMENTOS DE PROGRAMACION
2. Método de Ordenamiento de Inserción Binaria en C#
int auxiliar;
int q;
int izqui;
int dere;
for (int i = 0; i < numeros.Length; i++)
{
auxiliar = numeros[i];
izqui = 0;
dere = i - 1;
while (izqui <= dere)
{
q = ((izqui + dere) / 2);
if (auxiliar < numeros[q])
{
dere = q - 1;
}
else
{
izqui = q + 1;
}
j = i - 1;
while (j >= izqui)
{
numeros[j + 1] = numeros[j];
j = j - 1;
}
numeros[izqui] = auxiliar;
}
}
for (int i = 0; i < longitud; i++)
Console.WriteLine(" " + numeros[i]);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PruebaVector
{
class PruebaVector
{
private int[] vector;
3
Página
FUNDAMENTOS DE PROGRAMACION
{
Console.WriteLine("Metodo de Shell Sort");
Console.Write("Cuantos longitud del vector:");
string linea;
linea = Console.ReadLine();
int cant;
cant = int.Parse(linea);
vector = new int[cant];
for (int f = 0; f < vector.Length; f++)
{
Console.Write("Ingrese elemento "+(f+1)+": ");
linea = Console.ReadLine();
vector[f] = int.Parse(linea);
}
}
FUNDAMENTOS DE PROGRAMACION
Console.WriteLine("Vector ordenados en forma
ascendente");
for (int f = 0; f < vector.Length; f++)
{
Console.Write(vector[f]+" ");
}
Console.ReadKey();
}
namespace quicksort
{
class Class
{
static void Main()
{
int n;
5
FUNDAMENTOS DE PROGRAMACION
llenar b = new llenar(n);
}
}
class llenar
{
int h;
int[] vector;
public llenar(int n)
{
h = n;
vector = new int[h];
for (int i = 0; i < h; i++)
{
Console.Write("ingrese valor {0}: ", i + 1);
vector[i] = Int32.Parse(Console.ReadLine());
}
quicksort(vector, 0, h - 1);
mostrar();
}
if (primero < j)
{
6
FUNDAMENTOS DE PROGRAMACION
if (i < ultimo)
{
quicksort(vector, i, ultimo);
}
}
namespace Burbuja
{
class Burbuja
{
private int[] vector;
7
Página
FUNDAMENTOS DE PROGRAMACION
Console.WriteLine("Metodo de Burbuja");
Console.Write("Cuantos longitud del vector: ");
string linea;
linea = Console.ReadLine();
int cant;
cant = int.Parse(linea);
vector = new int[cant];
for (int f = 0; f < vector.Length; f++)
{
Console.Write("Ingrese elemento "+(f+1)+": ");
linea = Console.ReadLine();
vector[f] = int.Parse(linea);
}
}
pv.Imprimir();
Página
FUNDAMENTOS DE PROGRAMACION
}
}
do
{
for (int i = der; i >= izq; i--)
{
if (numeros[i - 1] > numeros[i])
{
aux = numeros[i - 1];
numeros[i - 1] = numeros[i];
numeros[i] = aux;
k = i;
}
}
izq = k + 1;
for (int i = izq; i <= der; i++)
{
if (numeros[i - 1] > numeros[i])
{
aux = numeros[i - 1];
numeros[i - 1] = numeros[i];
numeros[i] = aux;
k = 1;
}
9
Página
}
der = k - 1;
FUNDAMENTOS DE PROGRAMACION
}
while (der >= izq);
namespace MergeSort
{
class Program
{
static void Main(string[] args)
{
int[] nums = new int[40];
Console.WriteLine("Metodo de Merge Sort");
Console.Write("Cuantos longitud del vector: ");
string linea;
linea = Console.ReadLine();
int cant;
cant = int.Parse(linea);
nums = new int[cant];
for (int f = 0; f < nums.Length; f++)
{
Console.Write("Ingrese elemento " + (f + 1) + ": ");
linea = Console.ReadLine();
nums[f] = int.Parse(linea);
}
MergeSort(nums);
Console.WriteLine("Vector Ordenado Ascendentemente");
for (int i = 0; i < nums.Length; i++)
Console.Write(nums[i] + " ");
Console.ReadLine();
}
FUNDAMENTOS DE PROGRAMACION
//Condicion de parada
if (desde == hasta)
return;
b++;
}
Página
else
FUNDAMENTOS DE PROGRAMACION
{
result[i] = x[a];
a++;
}
}
}
else
{
if (a <= hasta1)
{
result[i] = x[a];
a++;
}
}
}
return result;
}
}
}
12
Página
FUNDAMENTOS DE PROGRAMACION