Indices
Esta es la clase Nodo
using System;
using System.Collections.Generic;
using System.Text;
namespace Generics
{
class Node<K,T,V,H>
{
public K Indice;
public T Campo1;
public V Campo2;
public H Campo3;
public Node<K, T, V, H> NextNode;
public Node()
{
Indice = default(K);
Campo1 = default(T);
Campo2 = default(V);
Campo3 = default(H);
NextNode = null;
}
/// <summary>
/// nodo registro
/// </summary>
/// <param name="indice"></param>
/// <param name="campo1"></param>
/// <param name="campo2"></param>
/// <param name="campo3"></param>
/// <param name="nextNode"></param>
public Node(K indice, T campo1,V campo2,H campo3, Node<K, T, V, H> nextNode)
{
Indice = indice;
Campo1 = campo1;
Campo2 = campo2;
Campo3 = campo3;
NextNode = nextNode;
}
}
}
La Clase ListaEnlazada
using System;
using System.Collections.Generic;
using System.Text;
namespace Generics
{
class ListaEnlazada<K,T,V,H> where K: IComparable<K>
{
Node<K, T, V, H> m_Head;
Node<K, T, V, H>[] nodeArray;
public static int count = 0;
public ListaEnlazada()
{
m_Head = new Node<K, T, V, H>();
}
public void AddHead(K indice, T campo1,V campo2,H campo3)
{
Node<K, T, V, H> newNode = new Node<K, T,V,H>(indice, campo1,campo2,campo3,
m_Head.NextNode);
m_Head.NextNode = newNode;
ListaEnlazada<K, T, V, H>.count++;
}
public Node<K,T,V,H>[] llenarArray()
{
int i = 0;
Node<K, T, V, H> current = m_Head;
nodeArray = new Node<K, T, V, H>[count];
while (current.NextNode != null)
{
nodeArray[i] = current;
current = current.NextNode;
i++;
}
return nodeArray;
}
public Node<K, T, V, H> Find(object key,int tipo)
{
Node<K, T, V, H> current = m_Head;
switch (tipo)
{
case 1:
while (current.NextNode != null)
{
if (current.Campo1 != null )
{
if ( current.Campo1.Equals((T)key))
{
break;
}
current = current.NextNode;
}
else
current = current.NextNode;
}
break;
case 0:
while (current.NextNode != null)
{
if (current.Indice.CompareTo((K)key) == 0)
break;
else
current = current.NextNode;
}
break;
case 2:
while (current.NextNode != null)
{
if (current.Campo1 != null)
{
if (current.Campo2.Equals((V)key))
{
break;
}
current = current.NextNode;
}
else
current = current.NextNode;
}
break;
case 3:
while (current.NextNode != null)
{
if (current.Campo1 != null)
{
if (current.Campo3.Equals((H)key))
{
break;
}
current = current.NextNode;
}
else
current = current.NextNode;
}
break;
}
return current;
}
}
}