You are on page 1of 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Listas
{
public class Node
{
public object Element;
public Node Link;
public Node()
{
Element = null;
Link = null;
}
public Node(object TheElement)
{
Element = TheElement;
Link = null;
}
}
public class LinkedList
{
protected Node header;
public LinkedList()
{
header = new Node("Header");
}
private Node Find(object item)
{
Node current = new Node();
current = header;
while (current.Element != item)
current = current.Link;
return current;
}
public void InsertAfter(object newItem, object after)
{
Node current=new Node();
Node newNode = new Node(newItem);
current = Find(after);
newNode.Link = current.Link;
current.Link = newNode;
}
public void InsertBefore(object newItem, object before)
{
Node current = new Node();
Node newNode = new Node(newItem);
current = FindPrevious(before);
newNode.Link = current.Link;
current.Link = newNode;
}
public void InsertFirst(object newItem)
{
Node current = new Node();
Node newNode = new Node(newItem);
current = header;
newNode.Link = current.Link;

current.Link = newNode;
}
private Node FindPrevious(object n)
{
Node current = header;
while (current.Link != null && current.Link.Element != n)
current = current.Link;
return current;
}
public void Remove(object n)
{
Node p = FindPrevious(n);
if (p.Link != null)
p.Link = p.Link.Link;
}
public void RemoveLast()
{
Node current = new Node();
current = header;
while (current.Link != null)
current = current.Link;
this.Remove(current.Element);
}
public void RemoveFirst()
{
Node current = new Node();
current = header;
this.Remove(current.Link.Element);
}
public void PrintList()
{
Node current = new Node();
current = header;
while (current.Link != null)
{
Console.WriteLine(current.Link.Element.ToString());
current = current.Link;
}
}
}
public class Actividad :IComparable
{
public string Nombre;
public int ID;
public string Tipo;
public string TiempoEstimado;
public string Estado;
public Actividad(string nombre, int id,string tipo,string tiempo,string
estado)
{
Nombre = nombre;
ID = id;
Tipo = tipo;
TiempoEstimado = tiempo;
Estado = estado;
}
public int CompareTo(object obj)
{
Actividad aux = (Actividad)obj;
return this.ID.CompareTo(aux.ID);

}
public override string ToString()
{
return "\tNombre: " + Nombre + "\tID: " + ID + "\tTipo: " + Tipo + "
\tTiempo: " + TiempoEstimado +"\tEstado:" + Estado;
}
}
class Program
{
static void Main(string[] args)
{
Console.SetWindowSize(120, 30);
LinkedList L1 = new LinkedList();
Actividad n1 = new Actividad("Hola 1", 123, "Manual", "Dos", "Pendie
nte");
Actividad n2 = new Actividad("Hola 2", 124, "Manual", "Dos", "Pendie
nte");
Actividad n3 = new Actividad("Hola 3", 125, "Manual", "Dos", "Pendie
nte");
Actividad n4 = new Actividad("Hola 4", 126, "Manual", "Dos", "Pendie
nte");
Actividad n5 = new Actividad("Hola 5", 127, "Manual", "Dos", "Pendie
nte");
L1.InsertAfter(n1,
L1.InsertAfter(n2,
L1.InsertAfter(n3,
L1.InsertAfter(n4,
L1.InsertAfter(n5,

"Header");
"Header");
"Header");
"Header");
"Header");

int a = n2.CompareTo(n1);
L1.InsertFirst(n2);
L1.InsertBefore(n1, n2);
L1.InsertFirst(n3);
L1.InsertAfter(n1, n3);
L1.RemoveLast();
L1.RemoveFirst();
Console.WriteLine("La Lista Enlazada Queda: ");
L1.PrintList();
Console.ReadLine();
}
}
}

You might also like