Código
using System; using System.Collections.Generic; using System.Text; namespace My_Agenda { class Program { static void Main(string[] args) { int n; string op; n = 0; do { op = Menu(); switch (op) { case "I": case "i": Insertar(ref alumno, ref n); break; case "E": case "e": Eliminar(ref alumno, ref n); break; /*case "O": case "o": Ordenar(ref alumno, ref n); break;*/ case "B": case "b": Buscar(ref alumno, ref n); break; case "L": case "l": Listar(ref alumno , ref n); break; default: { if (op != "S" && op != "s") Console.WriteLine("\nOpcion invalida!!!"); break; } } } while (op != "S" && op != "s"); } //Menu del Programa Principal public static string Menu() { string op; Console.WriteLine("\n\t\t\tMENU"); Console.WriteLine("\t\t\t====\n"); Console.WriteLine("\t(I)nsertar"); Console.WriteLine("\t(E)liminar"); Console.WriteLine("\t(O)rdenar"); Console.WriteLine("\t(B)uscar"); Console.WriteLine("\t(L)istar"); Console.WriteLine("\t(S)alir"); Console.Write("\n\tIngresar Opcion: "); op = Console.ReadLine(); return op; } public static int MenuInsertar() { int op; Console.Write("\n\tCuantos Desea Ingresar? "); op = int.Parse(Console.ReadLine()); return op; } public static int MenuEliminar() { int op; Console.Write("\n\t(1) Por Nombre"); Console.Write("\t(2) Por Posicion"); Console.Write("\t>>>Opcion: "); op = int.Parse(Console.ReadLine()); return op; } public static int MenuOrdenar() { int op; Console.Write("\n\t(1) Ascendente"); Console.Write("\t(2) Descendente"); Console.Write("\t>>>Opcion:"); op = int.Parse(Console.ReadLine()); return op; } public static int MenuBuscar() { int op; Console.Write("\n\t(1) Por Nombre"); Console.Write("\t(2) Por Posicion"); Console.Write("\t>>>Opcion: "); op = int.Parse(Console.ReadLine()); return op; } public static void Insertar(ref string[,] alumno, ref int n) { int op, i,j; op = MenuInsertar(); for (i = n; i < op + n; i++) { Console.WriteLine("\tALUMNO {0} ", i); for (j = 0; j < 4; j++) { if (j == 0) { Console.Write("\t\tNOMBRE : "); alumno[i, j] = Console.ReadLine(); } if (j == 1) { Console.Write("\t\tAPELLIDO : "); alumno[i, j] = Console.ReadLine(); } if (j == 2) { Console.Write("\t\tEDAD : "); alumno[i, j] = Console.ReadLine(); } if (j == 3) { Console.Write("\t\tTELEFONO : "); alumno[i, j] = Console.ReadLine(); } } } n = op + n; } public static void Eliminar(ref string[,] alumno, ref int n) { int op, p, i,j; string valor; op = MenuEliminar(); p = -1; switch (op) { case 1: { Console.Write("Nombre:"); valor = Console.ReadLine(); for (i = 0; i < n; i++) { for (j = 0; j < 1; j++) { if (valor == alumno[i, j]) { p = i; } } } if (p >= 0) { for (i = p; i < n - 1; i++) { for (j = 0; j < 4; j++) { if (j == 0) { alumno[i, j] = alumno[i + 1, j]; } if (j == 1) { alumno[i, j] = alumno[i + 1, j]; } if (j == 2) { alumno[i, j] = alumno[i + 1, j]; } if (j == 3) { alumno[i, j] = alumno[i + 1, j]; } } } n--; for (j = 0; j < 4; j++) { if (j == 0) { alumno[n, j] = ""; } if (j == 1) { alumno[n, j] = ""; } if (j == 2) { alumno[n, j] = ""; } if (j == 3) { alumno[n, j] = ""; } } } else { Console.WriteLine("Elemento No Encontrado"); } break; } case 2: { do { Console.Write("Posicion:"); p = int.Parse(Console.ReadLine()); } while (p >= n); if (p == n-1) { for (i = p; i < n - 1; i++) { for (j = 0; j < 4; j++) { if (j == 0) { alumno[i, j] = alumno[i + 1, j]; } if (j == 1) { alumno[i, j] = alumno[i + 1, j]; } if (j == 2) { alumno[i, j] = alumno[i + 1, j]; } if (j == 3) { alumno[i, j] = alumno[i + 1, j]; } } } n--; for (j = 0; j < 4; j++) { if (j == 0) { alumno[n, j] = ""; } if (j == 1) { alumno[n, j] = ""; } if (j == 2) { alumno[n, j] = ""; } if (j == 3) { alumno[n, j] = ""; } } } else { for (i = p; i < n - 1; i++) { for (j = 0; j < 4; j++) { if (j == 0) { alumno[i, j] = alumno[i + 1, j]; } if (j == 1) { alumno[i, j] = alumno[i + 1, j]; } if (j == 2) { alumno[i, j] = alumno[i + 1, j]; } if (j == 3) { alumno[i, j] = alumno[i + 1, j]; } } } n--; for (j = 0; j < 4; j++) { if (j == 0) { alumno[n, j] = ""; } if (j == 1) { alumno[n, j] = ""; } if (j == 2) { alumno[n, j] = ""; } if (j == 3) { alumno[n, j] = ""; } } } break; } default: Console.WriteLine("\nOpcion invalida!!!"); break; } } public static void Buscar(ref string [,] alumno, ref int n) { int op, i, p,j; string valor; op = MenuBuscar(); //Metodo de Busqueda Secuencial switch (op) { case 1: { Console.Write("Nombre:"); valor = Console.ReadLine(); for (i = 0; i < n; i++) { for (j = 0; j < 1; j++) { if (valor == alumno[i, j]) { Console.WriteLine("El Elemento Buscado se encuentra en la Posicion: {0}", i); } } } break; } case 2: { do { Console.Write("Posicion:"); p = int.Parse(Console.ReadLine()); } while (p >= n); for (i = 0; i < 100; i++) { if (i == p) { Console.WriteLine("El alumno Buscado es: "); for(j=0;j<4;j++) { if (j == 0) { Console.Write("NOMBRE: " + alumno[i, j]); } if (j == 1) { Console.Write("APELLIDO: " + alumno[i, j]); } if (j == 2) { Console.Write("EDAD: " + alumno[i, j]); } if (j == 3) { Console.Write("TELEFONO: " + alumno[i, j]); } } } } break; } default: Console.WriteLine("\nOpcion invalida!!!"); break; } } /*public static void Ordenar(ref string[] Elementos, ref int n, ref int m) { int op, i, j, indice, k; string Aux; op = MenuOrdenar(); switch (op) { case 1: { //Array.Sort(Elementos); //Metodo de Ordenamiento de Burbuja for (i = 0; i < n; i++) { indice = i; for (j = i + 1; j < n; j++) { k = Elementos[j].CompareTo(Elementos[indice]); if (k < 0) { indice = j; if (i != indice) { Aux = Elementos[i]; Elementos[i] = Elementos[indice]; Elementos[indice] = Aux; } } } } break; } case 2: { //Array.Sort(Elementos); Array.Reverse(Elementos); for (i = 0; i < n; i++) { indice = i; for (j = i + 1; j < n; j++) { k = Elementos[j].CompareTo(Elementos[indice]); if (k > 0) { indice = j; if (i != indice) { Aux = Elementos[i]; Elementos[i] = Elementos[indice]; Elementos[indice] = Aux; } } } } break; } default: Console.WriteLine("\nOpcion invalida!!!"); break; } }*/ public static void Listar(ref string[,] alumno, ref int n) { int i,j; if (n > 0) { for (i = 0; i < n; i++) { for (j = 0; j < 4; j++) { Console.Write(alumno[i,j]+" "); } Console.WriteLine(); } } else Console.WriteLine("\nLista Vacia!!!"); } } }
la parte del ordenamiento no lo puedo hacer
osea tiene que ordenarse alfabeticamente por nombre o por apellido
aver kkien me puede ayudar!!!