public DoubleLinkedListItem <T> FindRecursiv(T itemToFind, DoubleLinkedListItem <T> actItem = null) { //Parameter überprüfen if (itemToFind == null) { return(null); } //ist die DLL leer if (this._firstItem == null) { return(null); } //actItem == null bedeutet, dass FindRecursiv am Beginn der DLL starten soll if (actItem == null) { actItem = this._firstItem; } // ansonsten, soll der Zeiger auf das nächste Element gesetzt werden else { actItem = actItem.NextItem; } //actItem wird normalerweise auf actItem.NextItem gesetzt // => actItem könnte null sein (Ende der Liste) if (actItem == null) { return(null); } // ist das aktuelle Element das gesuchte Element else if (actItem.Item.Equals(itemToFind)) { return(actItem); } // ansonsten wurde das Element noch nicht gefunden und das // Ende der Liste wurde noch nicht erreicht else { //rekursiver Aufruf return(FindRecursiv(itemToFind, actItem)); } }
public bool ChangeItem(T itemToFind, T newData) { if (newData == null) { return(false); } DoubleLinkedListItem <T> foundItem = Find(itemToFind); if (foundItem == null) { return(false); } foundItem.Item = newData; return(true); }
public bool Change(T itemToChange, T itemNewData) { if ((itemToChange == null) || (itemNewData == null) || (this._firstItem == null)) { return(false); } DoubleLinkedListItem <T> foundItem = Find(itemToChange); if (foundItem == null) { return(false); } else { foundItem.Item = itemNewData; return(true); } }
public override string ToString() { string s = ""; if (this._firstItem != null) { DoubleLinkedListItem <T> actItem = this._firstItem; while (actItem != null) { s += actItem.Item.ToString() + "\n"; actItem = actItem.NextItem; } } if (s == "") { return("no Item"); } return(s); }
public DoubleLinkedListItem <T> Find(T itemToFind) { DoubleLinkedListItem <T> pointer = this._firstItem; if ((_firstItem == null) || (itemToFind == null)) { return(null); } while (pointer != null) { if (pointer.Item.Equals(itemToFind)) { return(pointer); } pointer = pointer.NextItem; } return(null); }
public bool Add(T itemToAdd) { if (itemToAdd == null) { return(false); } if (this._firstItem == null) { this._firstItem = new DoubleLinkedListItem <T>(itemToAdd, null, null); _lastItem = _firstItem; } else { this._lastItem.NextItem = new DoubleLinkedListItem <T>(itemToAdd, null, this._lastItem); this._lastItem = this._lastItem.NextItem; } return(true); }
//other Methods: public bool Add(T itemToAdd) { if (itemToAdd == null) { return(false); } if (_firstItem == null) { _firstItem = new DoubleLinkedListItem <T>(itemToAdd, null, null); _lastItem = _firstItem; return(true); } else { DoubleLinkedListItem <T> toAdd = new DoubleLinkedListItem <T>(itemToAdd, null, _lastItem); _lastItem.NextItem = toAdd; _lastItem = toAdd; return(true); } }
public bool Remove(T itemToRemove) { if (itemToRemove == null) { return(false); } if (this._firstItem == null) { return(false); } DoubleLinkedListItem <T> found = Find(itemToRemove); if (found == null) { return(false); } if (found.Equals(_firstItem.Item)) { _firstItem = _firstItem.NextItem; _firstItem.PreviousItem = null; return(true); } if (found == _lastItem) { _lastItem = _lastItem.PreviousItem; _lastItem.NextItem = null; return(true); } found.NextItem.PreviousItem = found.PreviousItem; found.PreviousItem.NextItem = found.NextItem; return(true); }
public DoubleLinkedList(DoubleLinkedList <T> list) { this._firstItem = list._firstItem; this._lastItem = list._lastItem; }
public DoubleLinkedList(T item) { this._firstItem = new DoubleLinkedListItem <T>(item, null, null); this._lastItem = null; }
public DoubleLinkedList() { this._firstItem = null; this._lastItem = null; }
public DoubleLinkedList(DoubleLinkedList <T> dll) { this._firstItem = dll._firstItem; this._lastItem = dll._lastItem; }
public DoubleLinkedListItem(T item, DoubleLinkedListItem <T> nextItem, DoubleLinkedListItem <T> itemBefore) { this.Item = item; this.NextItem = nextItem; this.ItemBefore = itemBefore; }
public DoubleLinkedListItem(T item, DoubleLinkedListItem <T> beforeItem, DoubleLinkedListItem <T> nextItem) { this.Item = item; this.BeforeItem = beforeItem; this.NextItem = nextItem; }
public DoubleLinkedListItem(T p, DoubleLinkedListItem <T> nextItem, DoubleLinkedListItem <T> previousItem) { this.Item = p; this.NextItem = nextItem; this.PreviousItem = previousItem; }