elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Foros Generales
| |-+  Dudas Generales (Moderador: engel lex)
| | |-+  agenda de 1000 numeros
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: agenda de 1000 numeros  (Leído 1,614 veces)
Sh¡kar!

Desconectado Desconectado

Mensajes: 4


Ver Perfil
agenda de 1000 numeros
« en: 1 Junio 2010, 21:55 pm »

hola les dejo este codigo ya lo hice con el metodo shell y busqueda lineal pero como lo puedo hacer q sea el metodo de insercion y busqueda binaria.

Código
  1.  


using System;
using System.Collections.Generic;
using System.Text;

namespace agenda_de_david
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] vec = new string[1000];
            string[] vecbus = new string[1000];
            int numreg = 0;
            string nom1 = "teofilo 03474534";
            vec[0] = nom1;
            string nom2 = "hugo 4561237895";
            vec[1] = nom2;
            string nom3 = "paco 4578912345";
            vec[2] = nom3;
            string nom4 = "luis 7894561253";
            vec[3] = nom4;
            string nom5 = "poncho 4213678945";
            vec[4] = nom5;
            string nom6 = "alvaro 4521378954";
            vec[5] = nom6;
            string nom7 = "naruto 5516960578";
            vec[6] = nom7;
            string nom8 = "sasuke 4878754021";
            vec[7] = nom8;
            string nom9 = "kakashi 4578922014";
            vec[8] = nom9;
            string nom10 = "haku 4567891230";
            vec[9] = nom10;
            string nom11 = "zabuza 45689123";
            vec[10] = nom11;
            string nom12 = "orochimaru 4561237895";
            vec[11] = nom12;
            string nom13 = "kabuto 4567891001";
            vec[12] = nom13;
            string nom14 = "kisame 4567891234";
            vec[13] = nom14;
            string nom15 = "itachi 4561237895";
            vec[14] = nom15;
            string nom16 = "david 4567891235";
            vec[15] = nom16;
            string nom17 = "pepe 7894562331";
            vec[16] = nom17;
            string nom18 = "jorge 7895554612";
            vec[17] = nom18;
            string nom19 = "carlos 7894561223 ";
            vec[18] = nom19;
            string nom20 = "vanesa 7894561234";
            vec[19] = nom20;
            string nom21 = "ana 4567891235";
            vec[20] = nom21;
            string nom22 = "gerardo 4578923123";
            vec[21] = nom22;
            string nom23 = "mario 4567891230";
            vec[22] = nom23;
            string nom24 = "maria 1234567890";
            vec[23] = nom24;
            string nom25 = "jose 10203078456";
            vec[24] = nom25;
            string nom26 = "eric 7894561230";
            vec[25] = nom26;
            string nom27 = "antonio 1245637821";
            vec[26] = nom27;
            string nom28 = "toño 1235478912";
            vec[27] = nom28;
            string nom29 = "tony 1203456702";
            vec[28] = nom29;
            string nom30 = "everardo 4561237895";
            vec[29] = nom30;
            string nom31 = "sakura 4562137895";
            vec[30] = nom31;
            string nom32 = "ino 4567891236";
            vec[31] = nom32;
            string nom33 = "chougi 4561237894";
            vec[32] = nom33;
            string nom34 = "akamaru 4562137895";
            vec[33] = nom34;
            string nom35 = "shikamaru 1203450123";
            vec[34] = nom35;
            string nom36 = "ioroi 7894521302";
            vec[35] = nom36;
            string nom37 = "fer 4567894561";
            vec[36] = nom37;
            string nom38 = "fernando 1234561289";
            vec[37] = nom38;
            string nom39 = "mosca 1234567889";
            vec[38] = nom39;
            string nom40 = "beto 1201010235";
            vec[39] = nom40;
            string nom41 = "alberto 1234567890";
            vec[40] = nom41;
            string nom42 = "sandra 1234447775";
            vec[41] = nom42;
            string nom43 = "pedro 0213456212";
            vec[42] = nom43;
            string nom44 = "juanita 1212145455";
            vec[43] = nom44;
            string nom45 = "perez 1234444555";
            vec[44] = nom45;
            string nom46 = "gonzalez 1234561232";
            vec[45] = nom46;
            string nom47 = "aniceto 1234562131";
            vec[46] = nom47;
            string nom48 = "victor 1234562210";
            vec[47] = nom48;
            string nom49 = "ignacio 1234562130";
            vec[48] = nom49;
            string nom50 = "fransisco 1234567412";
            vec[49] = nom50;
            string nomb1 = "teofilo";
            vecbus[0] = nomb1;
            string nomb2 = "hugo";
            vecbus[1] = nomb2;
            string nomb3 = "paco";
            vecbus[2] = nomb3;
            string nomb4 = "luis";
            vecbus[3] = nomb4;
            string nomb5 = "poncho";
            vecbus[4] = nomb5;
            string nomb6 = "alvaro";
            vecbus[5] = nomb6;
            string nomb7 = "naruto";
            vecbus[6] = nomb7;
            string nomb8 = "sasuke";
            vecbus[7] = nomb8;
            string nomb9 = "kakashi";
            vecbus[8] = nomb9;
            string nomb10 = "haku";
            vecbus[9] = nomb10;
            string nomb11 = "zabuza";
            vecbus[10] = nomb11;
            string nomb12 = "orochimaru";
            vecbus[11] = nomb12;
            string nomb13 = "kabuto";
            vecbus[12] = nomb13;
            string nomb14 = "kisame";
            vecbus[13] = nomb14;
            string nomb15 = "itachi";
            vecbus[14] = nomb15;
            string nomb16 = "david";
            vecbus[15] = nomb16;
            string nomb17 = "pepe";
            vecbus[16] = nomb17;
            string nomb18 = "jorge";
            vecbus[17] = nomb18;
            string nomb19 = "carlos";
            vecbus[18] = nomb19;
            string nomb20 = "vanesa";
            vecbus[19] = nomb20;
            string nomb21 = "ana";
            vecbus[20] = nomb21;
            string nomb22 = "gerardo";
            vecbus[21] = nomb22;
            string nomb23 = "mario";
            vecbus[22] = nomb23;
            string nomb24 = "maria";
            vecbus[23] = nomb24;
            string nomb25 = "jose";
            vecbus[24] = nomb25;
            string nomb26 = "eric";
            vecbus[25] = nomb26;
            string nomb27 = "antonio";
            vecbus[26] = nomb27;
            string nomb28 = "toño";
            vecbus[27] = nomb28;
            string nomb29 = "tony";
            vecbus[28] = nomb29;
            string nomb30 = "everardo";
            vecbus[29] = nomb30;
            string nomb31 = "sakura";
            vecbus[30] = nomb31;
            string nomb32 = "ino";
            vecbus[31] = nomb32;
            string nomb33 = "chougi";
            vecbus[32] = nomb33;
            string nomb34 = "akamaru";
            vecbus[33] = nomb34;
            string nomb35 = "shikamaru";
            vecbus[34] = nomb35;
            string nomb36 = "ioroi";
            vecbus[35] = nomb36;
            string nomb37 = "fer";
            vecbus[36] = nomb37;
            string nomb38 = "fernando";
            vecbus[37] = nomb38;
            string nomb39 = "mosca";
            vecbus[38] = nomb39;
            string nomb40 = "beto";
            vecbus[39] = nomb40;
            string nomb41 = "alberto";
            vecbus[40] = nomb41;
            string nomb42 = "sandra";
            vecbus[41] = nomb42;
            string nomb43 = "pedro";
            vecbus[42] = nomb43;
            string nomb44 = "juanita";
            vecbus[43] = nomb44;
            string nomb45 = "perez";
            vecbus[44] = nomb45;
            string nomb46 = "gonzalez";
            vecbus[45] = nomb46;
            string nomb47 = "aniceto";
            vecbus[46] = nomb47;
            string nomb48 = "victor";
            vecbus[47] = nomb48;
            string nomb49 = "ignacio";
            vecbus[48] = nomb49;
            string nomb50 = "fransisco";
            vecbus[49] = nomb50;
            Console.Title = "Agenda telefonica";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("                ..:::::::::..          ");
            Console.WriteLine("           ..:::aad8888888baa:::..      ");
            Console.WriteLine("        .::::d:?88888888888?::8b::::.           ");
            Console.WriteLine("      .:::d8888:?88888888??a888888b:::.       ");
            Console.WriteLine("    .:::d8888888a8888888aa8888888888b:::.       ");
            Console.WriteLine("   ::::dP::::::::88888888888::::::::Yb::::       ");
            Console.WriteLine("  ::::dP:::::::::Y888888888P:::::::::Yb::::         ");
            Console.WriteLine(" ::::d8:::::::::::Y8888888P:::::::::::8b::::     DAVID ABRAHAM VEGA   ");
            Console.WriteLine(".::::88::::::::::::Y88888P::::::::::::88::::.    CRISTOPHER MAGAÑA MORENO  ");
            Console.WriteLine(":::::Y8baaaaaaaaaa88P:T:Y88aaaaaaaaaad8P:::::      ");
            Console.WriteLine(":::::::Y88888888888P::|::Y88888888888P:::::::     ");
            Console.WriteLine("::::::::::::::::888:::|:::888::::::::::::::::  ");
            Console.WriteLine("`:::::::::::::::8888888888888b::::::::::::::'       ");
            Console.WriteLine(" :::::::::::::::88888888888888::::::::::::::      ");
            Console.WriteLine("  :::::::::::::d88888888888888:::::::::::::     ");
            Console.WriteLine("   ::::::::::::88::88::88:::88::::::::::::   ");
            Console.WriteLine("    `::::::::::88::88::88:::88::::::::::' ");
            Console.WriteLine("      `::::::::88::88::P::::88::::::::'");
            Console.WriteLine("        `::::::88::88:::::::88::::::");
            Console.WriteLine("           ``:::::::::::::::::::");
            Console.WriteLine("                ``:::::::::''");
            Console.WriteLine();
            Console.WriteLine("PRESS KEY");
            Console.ReadKey();
            goto inicio;


        inicio:
            try
            {
                int opc = 0;
                Console.Clear();
                do
                {


                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Elige una opcion");
                    Console.WriteLine();
                    Console.WriteLine("Hacer un registro..................1");
                    Console.WriteLine();
                    Console.WriteLine("Buscar.............................2");
                    Console.WriteLine();
                    Console.WriteLine("Mostrar registro...................3");
                    Console.WriteLine();
                    Console.WriteLine("Salir..............................4");
                    Console.WriteLine();
                    Console.Write("que deseas hacer: ");
                    opc = int.Parse(Console.ReadLine());



                } while (opc < 1 || opc > 4);
                Console.Clear();


                switch (opc)
                {
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        string nom;
                        Console.WriteLine("Cuantos registros vas a hacer??");
                        numreg = int.Parse(Console.ReadLine());

                        for (int inj = 50; inj < numreg + 50; inj++)
                        {
                            Console.Clear();
                            Console.WriteLine("Cual es el nombre??");
                            nom = Console.ReadLine();
                            Console.WriteLine("Cual es tu numero??");
                            string nu = Console.ReadLine();
                            vecbus[inj] = nom;
                            string nn = nom + " " + nu;
                            vec[inj] = nn;
                        }
                        //Descomponer el nombre en la primera letra

                        char[] veclec = new char[numreg + 50];
                        int[] guardar = new int[numreg + 50];
                        for (int ifo = 0; ifo < numreg + 50; ifo++)
                        {


                            char[] dato = vecbus[ifo].ToCharArray();
                            //Vec almacena la primera letra
                            veclec[ifo] = dato[0];
                            if (veclec[ifo] == 'a')
                                guardar[ifo] = 1;
                            if (veclec[ifo] == 'b')
                                guardar[ifo] = 2;
                            if (veclec[ifo] == 'c')
                                guardar[ifo] = 3;
                            if (veclec[ifo] == 'd')
                                guardar[ifo] = 4;
                            if (veclec[ifo] == 'e')
                                guardar[ifo] = 5;
                            if (veclec[ifo] == 'f')
                                guardar[ifo] = 6;
                            if (veclec[ifo] == 'g')
                                guardar[ifo] = 7;
                            if (veclec[ifo] == 'h')
                                guardar[ifo] = 8;
                            if (veclec[ifo] == 'i')
                                guardar[ifo] = 9;
                            if (veclec[ifo] == 'j')
                                guardar[ifo] = 10;
                            if (veclec[ifo] == 'k')
                                guardar[ifo] = 11;
                            if (veclec[ifo] == 'l')
                                guardar[ifo] = 12;
                            if (veclec[ifo] == 'm')
                                guardar[ifo] = 13;
                            if (veclec[ifo] == 'n')
                                guardar[ifo] = 14;
                            if (veclec[ifo] == 'ñ')
                                guardar[ifo] = 15;
                            if (veclec[ifo] == 'o')
                                guardar[ifo] = 16;
                            if (veclec[ifo] == 'p')
                                guardar[ifo] = 17;
                            if (veclec[ifo] == 'q')
                                guardar[ifo] = 18;
                            if (veclec[ifo] == 'r')
                                guardar[ifo] = 19;
                            if (veclec[ifo] == 's')
                                guardar[ifo] = 20;
                            if (veclec[ifo] == 't')
                                guardar[ifo] = 21;
                            if (veclec[ifo] == 'u')
                                guardar[ifo] = 22;
                            if (veclec[ifo] == 'v')
                                guardar[ifo] = 23;
                            if (veclec[ifo] == 'w')
                                guardar[ifo] = 24;
                            if (veclec[ifo] == 'x')
                                guardar[ifo] = 25;
                            if (veclec[ifo] == 'y')
                                guardar[ifo] = 26;
                            if (veclec[ifo] == 'z')
                                guardar[ifo] = 27;
                        }

                        //shell

                        //int salto, k, j, aux;
                        //string auxtex, auxnombus;
                        //int ord;
                        //salto = numreg + 50;
                        //while (salto > 1)
                        //{
                        //    salto = salto / 2;
                        //    do
                        //    {
                        //        ord = 1;
                        //        for (j = 0; j <= (numreg + 50) - 1 - salto; j = j + salto)
                        //        {
                        //            k = j + salto;
                        //            if (guardar[j] > guardar[k])
                        //            {
                        //                aux = guardar[j];
                        //                auxtex = vec[j];
                        //                auxnombus = vecbus[j];
                        //                guardar[j] = guardar[k];
                        //                vec[j] = vec[k];
                        //                vecbus[j] = vecbus[k];
                        //                guardar[k] = aux;
                        //                vec[k] = auxtex;
                        //                vecbus[k] = auxnombus;
                        //                ord = 0;
                        //            }
                        //        }

                        //    }
                        //    while (ord == 0);
                        //}
                        goto inicio;

                    case 2:
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("Cual es el nombre que deseas buskar ??");
                        string bus = Console.ReadLine();
                        for (int ibus = 0; ibus < 1000; ibus++)
                        {
                            if (vecbus[ibus] == bus)
                                Console.WriteLine("Se encontro " + vec[ibus] + " en la posicion {0}", ibus + 1);
                        }
                        Console.ReadKey();
                        goto inicio;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Green;
                        for (int inm = 0; inm < numreg + 50; inm++)
                        {
                            if (vec[inm] != " ")
                                Console.WriteLine(vec[inm]);
                        }
                        Console.ReadKey();
                        goto inicio;

                    case 4:
                        break;

                }
            }
            catch
            {
                Console.Clear();
                goto inicio;
            }
        }
    }
}


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines