public void Eliminar_especifico(int valor) { Nodo *aux = Inicio; if (aux->info.numero == valor) { Nodo *temp = Inicio; Inicio = aux->siguiente; Inicio->anterior = null; Marshal.FreeHGlobal((IntPtr)temp); temp = null; } else { if (ExisteValor(valor)) { while (aux->siguiente->info.numero != valor) { aux = aux->siguiente; } Nodo *temp = aux->siguiente; aux->siguiente = aux->siguiente->siguiente; aux->siguiente->anterior = aux; Marshal.FreeHGlobal((IntPtr)temp); temp = null; } } }
public void EliminarInicio() { Nodo *temp = Inicio; Inicio = Inicio->siguiente; Inicio->anterior = null; Marshal.FreeHGlobal((IntPtr)temp); temp = null; }
public void Eliminar(int Indice) { if (Indice < 0) { throw new ArgumentOutOfRangeException("Indice: " + Indice); } if (this.Vacio) { //return null; } if (Indice >= this.Tamaño) { Indice = Tamaño - 1; } Nodo *Elimina = this.Cabeza; if (this.Cabeza == null) { Tamaño = 1; } else if (this.Cabeza->Siguiente == null) { Marshal.FreeHGlobal((IntPtr)Cabeza); this.Cabeza = null; } else if (Indice >= Tamaño) { Nodo *Final = Cabeza; while (Final->Siguiente->Siguiente != null) { Final = Final->Siguiente; } Elimina = Final->Siguiente; Final->Siguiente = null; Marshal.FreeHGlobal((IntPtr)Elimina); Elimina = null; } else { Nodo *Actual = this.Cabeza; for (int i = 0; i < Indice - 1; i++) { Actual = Actual->Siguiente; } Elimina = Actual->Siguiente; Actual->Siguiente = Actual->Siguiente->Siguiente; Marshal.FreeHGlobal((IntPtr)Elimina); } Tamaño--; }
public void InsertarOrden(Data datos) { Nodo *nuevo = (Nodo *)Marshal.AllocHGlobal(sizeof(Nodo)); nuevo->info = datos; if (Inicio == null) { Inicio = nuevo; Fin = nuevo; } else { if (nuevo->info.numero < Inicio->info.numero) { nuevo->siguiente = Inicio; Inicio->anterior = nuevo; Inicio = nuevo; } else { Nodo *temp1 = Inicio; while ((nuevo->info.numero > temp1->info.numero) && (temp1 != Fin)) { if (nuevo->info.numero <= temp1->siguiente->info.numero) { break; } temp1 = temp1->siguiente; } if (temp1 == Fin) { nuevo->siguiente = temp1->siguiente; nuevo->anterior = temp1; temp1->siguiente = nuevo; Fin = nuevo; } else { nuevo->siguiente = temp1->siguiente; temp1->siguiente->anterior = nuevo; nuevo->anterior = temp1; temp1->siguiente = nuevo; } } } }
public int IndiceDe(Data dato) { Nodo *Actual = this.Cabeza; for (int i = 0; i < this.Tamaño; i++) { if (Actual->Info.Equals(dato)) { return(i); } Actual = Actual->Siguiente; } return(-1); }
public void Eliminar_ultimo() { Nodo *aux = Inicio; while (aux->siguiente != Fin) { aux = aux->siguiente; } Nodo *temp = aux->siguiente; aux->siguiente = null; Fin = aux; Marshal.FreeHGlobal((IntPtr)temp); temp = null; }
public void InsertarFinal(Data datos) { Nodo *nuevo = (Nodo *)Marshal.AllocHGlobal(sizeof(Nodo)); nuevo->info = datos; if (Inicio == null) { Inicio = nuevo; Fin = nuevo; } else { Fin->siguiente = nuevo; nuevo->anterior = Fin; Fin = nuevo; } }
public bool ExisteValor(int valor) { bool existe = false; Nodo *aux = Inicio; while (aux != Fin) { if (aux->info.numero == valor) { existe = true; break; } else { aux = aux->siguiente; } } return(existe); }
private object Insertar(int Indice, Data dato) { if (Indice < 0) { throw new ArgumentOutOfRangeException("Indice: " + Indice); } if (Indice > Tamaño) { Indice = Tamaño; } Nodo *Actual = (Nodo *)Marshal.AllocHGlobal(sizeof(Nodo)); Actual->Info = dato; Actual->Ultimo = true; if (this.Vacio || Indice == 0) { this.Cabeza = Actual; Actual->Siguiente = this.Cabeza; } else { Nodo *Final = this.Cabeza; while (Final->Ultimo != true) { Final = Final->Siguiente; } Final->Ultimo = false; Final->Siguiente = Actual; Actual->Siguiente = this.Cabeza; } Tamaño++; return(dato); }
public object Obtener(int Indice) { if (Indice < 0) { throw new ArgumentOutOfRangeException("Indice: " + Indice); } if (this.Vacio) { return(null); } if (Indice >= this.Tamaño) { Indice = this.Tamaño - 1; } Nodo *Actual = this.Cabeza; for (int i = 0; i < Indice; i++) { Actual = Actual->Siguiente; } return(Actual->Info); }
public ListaDoblementeEnlazada() { Inicio = null; Fin = null; }
public ListaCircular() { this.Cabeza = null; this.Tamaño = 0; }
public void Limpiar() { this.Cabeza = null; this.Tamaño = 0; }