Este es lo mismo que el anterior solo que usando string
//@siddexter
//proyectmaker
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
class Ordenamiento
{
string temp;
public int N = 15, M = 15, NM = 31;
int r = 0;
public string[]B;
public string[] A;
public string[] C = new string [32];
public void generar()
{
B = new [] { "Zacatecas", "Veracruz", "Tamaulipas", "Sonora ", "SL Potosí", "Querétaro", "Oaxaca",
"Nayarit", "Michoacán", "Jalisco", "Guerrero", "A.Calientes", "Durango", "Chihuahua", "Colima", "Campeche" };
A = new[] { "BC Norte", "BC Sur.", "Coahuila", "Chiapas", "D.Federal", "Guanajuato", "Hidalgo",
"México", "Morelos", "N. León", "Puebla", "Q Roo", "Sinaloa", "Tabasco", "Tlaxcala", "Yucatán" };
}
public void desA()
{
//arreglo A desordenado
Console.WriteLine("\n\t...Vector A desordenado...\n");
for (int i = 0; i <= N; i++)
{
Console.Write("\t{0}-{1}",i+1, A[i]);
if(r==5)
{
Console.WriteLine();
r = 0;
}
r++;
}
}
public void ordeA()
{
string temp = "";
for (int k = 0; k <= N; k++)
{
for (int L = 0; L < N - k; L++)
{
int y =((A[L])).CompareTo((A[L+1]));
if (y > 0)
{
temp = A[L];
A[L] = A[L + 1];
A[L + 1] = temp;
}
}
}
//arreglo A ordenado
Console.WriteLine("\n\n\t...Vector A ordenado...\n");
for (int c = 0; c <= N; c++)
{
Console.Write("\t{0}-{1}", c + 1, A[c]);
if (r == 5)
{
Console.WriteLine();
r = 0;
}
r++;
}
}
public void desB()
{
Console.WriteLine("\n\n\t...Vector B desordenado...\n");
for (int i = 0; i <= M; i++)
{
//Console.Write(".{0}.", B[i]);
Console.Write("\t{0}-{1}", i + 1, B[i]);
if (r == 5)
{
Console.WriteLine();
r = 0;
}
r++;
}
}
public void ordeB()
{
//ordenamiento burbuja para B
temp = "";
for (int k = 0; k <= M; k++)
{
for (int L = 0; L < M - k; L++)
{
int u = ((B[L])).CompareTo((B[L + 1]));
if (u > 0)
{
temp = B[L];
B[L] = B[L + 1];
B[L + 1] = temp;
}
}
}
//arreglo B ordenado
Console.WriteLine("\n\n\t...Vector B ordenado...\n");
for (int c = 0; c <= M; c++)
{
// Console.Write(".{0}.", B[c]);
Console.Write("\t{0}-{1}", c + 1, B[c]);
if (r == 5)
{
Console.WriteLine();
r = 0;
}
r++;
}
}
public void InterSimple()
{
//intercalacion
int I = 0, J = 0, K = 0;
while (I <= N && J <= M)
{
int s=((A[I])).CompareTo((B[J]));
if (s <= 0)
{
C[K] = A[I];
I++; K++;
}
else
{
C[K] = B[J];
J++; K++;
}
}
if (I > N)
{
for (int x = J; x <= M; x++)
{
C[K] = B[x];
K++;
}
}
else
{
for (int x = I; x <= N; x++)
{
C[K] = A[x];
K++;
}
}
}
public void VectorC()
{
//arreglo C ordenado
Console.WriteLine("\n\n\t...Vector C...\n");
for (int c = 0; c <= NM; c++)
{
Console.Write("\t{0}-{1}", c + 1, C[c]);
if (r == 5)
{
Console.WriteLine();
r = 0;
}
r++;
}
}
}
static void Main(string[] args)
{
Ordenamiento obj = new Ordenamiento();
int op;
do
{
Console.Clear();
Console.WriteLine("\n\n\t\tMenu Ordenacion externa");
Console.WriteLine("\t\tNumeros de control");
Console.WriteLine("\n\n\t\t1-Generar valores");
Console.WriteLine("\t\t2-Desplegar A y B");
Console.WriteLine("\t\t3-Ordenar");
Console.WriteLine("\t\t4-Intercalar");
Console.WriteLine("\t\t5-Desplegar C");
Console.WriteLine("\t\t6-Salir");
Console.Write("\n\nOpcion:");
op = int.Parse(Console.ReadLine());
switch (op)
{
case 1:
Console.Clear();
obj.generar();
Console.WriteLine("enter");
Console.ReadLine();
break;
case 2:
obj.desA();
obj.desB();
Console.ReadLine();
break;
case 3:
Console.Clear();
obj.ordeA();
obj.ordeB();
Console.WriteLine("Ordenados");
Console.ReadLine();
break;
case 4:
Console.Clear();
obj.InterSimple();
Console.WriteLine("Intercalados");
Console.ReadLine();
break;
case 5:
Console.Clear();
obj.desA();
obj.desB();
obj.VectorC();
Console.ReadLine();
break;
default:
Console.WriteLine("Opcion invalida");
Console.ReadLine();
break;
}
} while (op != 6);
}
}
}
Visual Studio 2008
C#
Modo Consola

[Descarga]