Está en la página 1de 6

INSTITUTO TECNOLOGICO SUPERIOR DEL OCCIDENTE DEL

ESTADO DE HIDALGO
ING. EN SISTEMAS COMPUTACIONALES

ESTRUCTURA DE DATOS

3-A

Tabla de Dispersin

ALUMNO: RICARDO JIMENEZ MICETE Y LUIS FELIPE PEREZ CRUZ

MAESTRO: GUILLERMO CASTAEDA ORTIZ

Diagrama de la clase mData

Clase mData
- int[] datos;
+ mData(int position, string
datum):int
+setPosition(int)
+getPosition():int
+setDatum(int)
+getDatum():int
Cdigo

de la clase mData

class mData
{
public mData(int position, string datum)
{
Position = position;
Datum = datum;
}
public mData(int position)
{
Position = position;
}
private int position;
public int Position
{
get { return position; }
set { position = value; }
}
private string datum;
public string Datum
{
get { return datum; }
set { datum = value; }
}
}

Diagrama de la clase Nodo

cd Class Model


Nodo













private Nodo der;


internal Nodo Der //Metodo Derecha
{
get { return der; }
set { der = value; }
}
}

Form1













Nodo()
Nodo(int)
setDato(int)
getDato() : int
setIzq(Nodo)
getIzq() : Nodo
setDer(Nodo)
getDer() : Nodo

public string Dato //Metodo Dato


{
get { return dato; }
set { dato = value; }
}





+
+
+
+
+
+
+
+

Cdigo de la clase Nodo





dato: int
izq: Nodo
der: Nodo

class Nodo
{
private string dato;





Codigo de la clase Form1


public partial class Form1 : Form

private
private
private
private

int posicion;
Nodo[] nodos;
string[] arregloDatos;
int codigo;

public Form1()
{
InitializeComponent();
nodos = new Nodo[11];
arregloDatos = new string[50];
posicion = -1;
codigo = 0;
agregarPalabras();
mostrar();
}
private void agregarPalabras() //inserccion de datos
{
arregloDatos[0] = "Juan";
arregloDatos[1] = "Carlos";
arregloDatos[2] = "Orlando";
arregloDatos[3] = "Enrique";
arregloDatos[4] = "Mario";
arregloDatos[5] = "Maria";
arregloDatos[6] = "Pablo";
arregloDatos[7] = "Mateo";
arregloDatos[8] = "Oscar";
arregloDatos[9] = "Ana";
arregloDatos[10] = "Ricardo";
arregloDatos[11] = "Ian";
arregloDatos[12] = "Ines";
arregloDatos[13] = "Felipe";
arregloDatos[14] = "Miguel";
arregloDatos[15] = "Elefante";
arregloDatos[16] = "Aguila";
arregloDatos[17] = "Puma";
arregloDatos[18] = "Leon";
arregloDatos[19] = "Tigre";
arregloDatos[20] = "Vaca";
arregloDatos[21] = "Perro";
arregloDatos[22] = "Gato";
arregloDatos[23] = "Venado";
arregloDatos[24] = "Hipopotamo";
arregloDatos[25] = "Mono";
arregloDatos[26] = "Mariposa";
arregloDatos[27] = "Puerco";
arregloDatos[28] = "Jaguar";
arregloDatos[29] = "Armenia";
arregloDatos[30] = "Australia";
arregloDatos[31] = "Belgica";
arregloDatos[32] = "Afganistan";
arregloDatos[33] = "Alemania";
arregloDatos[34] = "Mexico";
arregloDatos[35] = "Portugal";
arregloDatos[36] = "Micronesia";
arregloDatos[37] = "Nigeria";
arregloDatos[38] = "Noruega";
arregloDatos[39] = "Pakistan";
arregloDatos[40] = "Qatar";
arregloDatos[41] = "Peru";
arregloDatos[42] = "Paraguay";
arregloDatos[43] = "Polonia";
arregloDatos[44] = "Rusia";
arregloDatos[45] = "Samoa";

arregloDatos[46]
arregloDatos[47]
arregloDatos[48]
arregloDatos[49]

=
=
=
=

"Siria";
"Singapur";
"Yemen";
"Venezuela"; // ultimo

foreach (string item in arregloDatos)


{
if (item == null)
{
break;
}
Nodo n = new Nodo();
n.Dato = item;
codigo = funcionHash(item);
posicion = codigo % 11;
if (nodos[posicion] == null)
{
nodos[posicion] = n;
}
else
{
nodos[posicion].Der = n;
}
}

public int funcionHash(string dat) //Funcion Hash


{
int hash = 0;
char[] letras = dat.ToCharArray();
foreach (char item in letras)
{
hash += (int)item;
}
return hash;
}
private void button1_Click(object sender, EventArgs e) //boton buscar
{
string datoBuscar = textBox1.Text;
int r = busqueda(datoBuscar);
if(r == 0)
{
textBox2.Text = "No encontrado";
}
else
{
textBox2.Text = "Encontrado";
}
}
public int busqueda(string dato) //Metodo de busqueda de dato
{
int codigo = funcionHash(dato);
posicion = codigo % 11;
int r = 0;
Nodo n = nodos[posicion];
while (n != null)
{
if (n.Dato.Equals(dato))
{
r = 1;
break;

}
else
{
n = n.Der;
}

}
return r;

public void mostrar() //Muestra los datos


{
for (int i = 0; i < nodos.Length; i++)
{
richTextBox1.AppendText(Convert.ToString(i) + ":\t");
Nodo n = nodos[i];
while(n != null)
{
richTextBox1.AppendText(n.Dato + " -> ");
n = n.Der;
}
richTextBox1.AppendText("\n");
}
}

Ejecucin

También podría gustarte