Beispiel #1
0
        public Arbol crearArbol(List <Arbol> codificacion)
        {
            //aqui construye el arbol
            Arbol decodif = new Arbol();

            for (int i = 0; i < codificacion.Count; i++)
            {
                string letra = codificacion[i].letra;

                string codigoBin = codificacion[i].clave;

                Arbol temp = decodif;

                for (int j = 0; j < codigoBin.Length; j++)
                {
                    if (codigoBin[j] == '0')
                    {
                        if (temp.hijoIzq == null)
                        {
                            temp.hijoIzq = new Arbol();
                        }
                        temp = temp.hijoIzq;
                    }
                    else
                    {
                        if (temp.hijoDer == null)
                        {
                            temp.hijoDer = new Arbol();
                        }
                        temp = temp.hijoDer;
                    }

                    if (j == codigoBin.Length - 1)
                    {
                        temp.letra = letra;
                    }
                }
                temp = decodif;
            }
            return(decodif);
        }
Beispiel #2
0
        private string traducir()
        {
            string[]     textCod;
            string       texto;
            List <Arbol> codific = new List <Arbol>();

            try
            {
                StreamReader sr = new StreamReader("morseDictionary.txt");
                texto = sr.ReadLine();
                while (texto != null)
                {
                    Arbol temp = new Arbol();
                    temp.letra = texto;
                    texto      = sr.ReadLine();
                    temp.clave = texto;
                    codific.Add(temp);
                    Console.WriteLine(temp.letra + " " + temp.clave);
                    texto = sr.ReadLine();
                }
                sr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("excepcion : " + ex.Message);
            }

            Arbol arbol = crearArbol(codific);

            textCod = textBox1.Text.Split(' ');

            for (int i = 0; i < textCod.Length; i++)
            {
                textoDec += decodificacion(arbol, textCod[i]);
            }

            return(textoDec);
        }
Beispiel #3
0
 public virtual void colocaDer(Arbol V, Arbol t)
 {
     t.hijoDer = V;
 }
Beispiel #4
0
 public virtual void colocaIzq(Arbol V, Arbol t)
 {
     t.hijoIzq = V;
 }
Beispiel #5
0
 public Arbol()
 {
     hijoIzq = null;
     hijoDer = null;
 }