Esempio n. 1
0
    public static void main(String args)
    {
        Scanner  teclado = new Scanner();
        int      key;
        Registro r1 = new Registro(789, "Registro 1");
        Registro r2 = new Registro(889, "Registro 2");

        Console.WriteLine(r1.hashCode());
        Console.WriteLine(r2.hashCode());
        // Registro r1, r2, r3, r4;
        MapaHash mapa = new MapaHash();

        mapa.put(new Registro(7865, "Isidro"));
        mapa.put(new Registro(123, "Josineidson"));
        mapa.put(new Registro(987, "Nilsonclecio"));
        mapa.put(new Registro(9832, "Deosdedite"));
        do
        {
            Console.WriteLine("Digite um codigo de registro");
            key = teclado.nextInt();
            if (key != -1)
            {
                Registro r = mapa.get(key);
                if (r != null)
                {
                    Console.WriteLine("Registro Recuperado = " + r.getKey() + " - " + r.getValue());
                }
                else
                {
                    Console.WriteLine("Registro nao existente");
                }
            }
        } while (key != -1);
        teclado.close();
    }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string texto;
            int    chave, continua;

            MapaHash mapa = new MapaHash();
            Registro dados;

            do
            {
                Console.Write("\nDigite uma chave: ");
                chave = int.Parse(Console.ReadLine());

                Console.Write("Digite um valor: ");
                texto = Console.ReadLine();

                dados = new Registro(chave, texto);
                mapa.push(dados);

                Console.Write("\nContinua (1-sim / 0-não): ");
                continua = int.Parse(Console.ReadLine());
            } while (continua != 0);

            Console.WriteLine("\n\n::::::::::::::::::::::::::::::::");

            do
            {
                Console.Write("Digite um chave: ");
                chave = int.Parse(Console.ReadLine());
                dados = mapa.get(chave);

                if (chave != -1)
                {
                    if (dados != null)
                    {
                        Console.WriteLine($"Registro = {dados.getValue()}");
                    }

                    else
                    {
                        Console.WriteLine("Não existe");
                    }
                }
            } while (chave != -1);
        }
    public static void main(String args)
    {
        String   texto;
        int      chave;
        int      continua;
        MapaHash mapa = new MapaHash();
        Registro r;

        do
        {
            Console.WriteLine("Digite uma chave");
            texto = teclado.next();
            chave = Integer.parseInt(texto);
            Console.WriteLine("Digite um valor");
            texto = teclado.next();
            r     = new Registro(chave, texto);
            mapa.put(r);
            Console.WriteLine("Continua? (1-sim / 0- nao)");
            continua = Integer.parseInt(teclado.next());
        } while (continua != 0);
        Console.WriteLine("========================================");
        do
        {
            Console.WriteLine("Digite uma chave");
            chave = Integer.parseInt(teclado.next());
            if (chave != -1)
            {
                r = mapa.get(chave);
                if (r != null)
                {
                    Console.WriteLine("Registro = " + r.getValue());
                }
                else
                {
                    Console.WriteLine("Nao existe");
                }
            }
        } while (chave != -1);
        teclado.close();
    }