CLR: .Net / Mono / Boo / Otros CLR > C#

 Arreglos Multidimensionales y ordenamiento

<< < (2/2)

DanielC#:
Hola a todos.
Bueno creo haber logrado lo que pretendía, seguramente se puede mejorar pero para mis conocimientos actuales me sirve.-
Dejo el programa porque considero que puede ser de ayuda para algún principiante, gracias gabio2 por tú tiempo.-


--- Código: C# ---using System; namespace ArrayDaniel{    class Entorno    {        public void entorno()        {            Console.Title = " Array ordenado";            Console.WindowHeight = 30;            Console.WindowWidth  = 70;            Console.BackgroundColor = ConsoleColor.Blue;            Console.ForegroundColor = ConsoleColor.Yellow;            Console.Clear();        }    }}

--- Código: C# ---using System; namespace ArrayDaniel{    class ProgramaApp    {        static void Main(string[] argumentos)        {            Entorno ent = new Entorno();            ent.entorno();            AgregarNombres anc = new AgregarNombres();            anc.agrNombres();             Console.ReadKey();        }    }}

--- Código: C# ---using System;using System.Text.RegularExpressions; namespace ArrayDaniel{    class AgregarNombres    {        public void agrNombres()        {            int cant = 0;            while(true)            {                Console.SetCursorPosition(02,02);                Console.Write("Ingrese la cantidad de personas(máximo 10)...:");                if(Int32.TryParse(Console.ReadLine(), out cant))                {                    if (cant > 0 && cant < 11) { break; }                }            }                        Regex reg = new Regex("^[A-Za-z ]+$");            byte _top = 4;            string[,] nombres = new string[cant,2];            string codigo = "";            byte auxCodigo = 0;            for(byte i = 0; i<cant; i++)            {                auxCodigo++;                codigo = Convert.ToString(auxCodigo);                while (true)                {                    Console.SetCursorPosition(02, _top);                    Console.Write("Ingrese nombre....:");                    string linea = Console.ReadLine();                    if (!string.IsNullOrEmpty(linea) && reg.IsMatch(linea))                    {                         nombres[i, 0] = linea;                        nombres[i, 1] = codigo;                        break;                    }                }                _top += 2;            }            Ordenar OrdenarArray = new Ordenar();            OrdenarArray.ordenar(nombres);         }    }}

--- Código: C# ---using System; namespace ArrayDaniel{    class Ordenar    {        public void ordenar(string [,] _array)        {            bool huboCambio = true;            byte _top = 2, col = 0;            int maxim = _array.Length/2;            while (huboCambio)            {                huboCambio = false;                for (byte Row = 0; Row < maxim-1; Row++)                {                    if (_array[Row, col].CompareTo(_array[Row+1, col]) > 0)                    {                        string auxNomb  = _array[Row, col];                        _array[Row, col] = _array[Row+1, col];                        _array[Row+1, col] = auxNomb;                        huboCambio = true;                        string auxCodi = _array[Row, col+1];                        _array[Row, col+1] = _array[Row + 1, col+1];                        _array[Row + 1, col+1] = auxCodi;                    }                }            }            Console.Clear();            Console.SetCursorPosition(02, _top);            Console.Write(" === Ordenado por nombre ===");            _top +=2;            Console.SetCursorPosition(02,_top);            Console.Write(" Código    nombre");            _top +=2;                        for (byte Row = 0; Row < maxim; Row++)            {                Console.SetCursorPosition(02, _top);                Console.WriteLine("      {0}    {01}", _array[Row, 1], _array[Row, 0]);                _top++;            }         }    }}
Saludos.
Daniel

gabio2:
DanielC# muyyy bien, tú solución hasta hoy es la mejor que conozco.

excelente. :)

Navegación

[0] Índice de Mensajes

[*] Página Anterior

Ir a la versión completa