예제 #1
0
        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));
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        //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);
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
 public DoubleLinkedList(DoubleLinkedList <T> list)
 {
     this._firstItem = list._firstItem;
     this._lastItem  = list._lastItem;
 }
예제 #10
0
 public DoubleLinkedList(T item)
 {
     this._firstItem = new DoubleLinkedListItem <T>(item, null, null);
     this._lastItem  = null;
 }
예제 #11
0
 public DoubleLinkedList()
 {
     this._firstItem = null;
     this._lastItem  = null;
 }
예제 #12
0
 public DoubleLinkedList(DoubleLinkedList <T> dll)
 {
     this._firstItem = dll._firstItem;
     this._lastItem  = dll._lastItem;
 }
예제 #13
0
 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;
 }
예제 #15
0
 public DoubleLinkedListItem(T p, DoubleLinkedListItem <T> nextItem, DoubleLinkedListItem <T> previousItem)
 {
     this.Item         = p;
     this.NextItem     = nextItem;
     this.PreviousItem = previousItem;
 }