Ejemplo n.º 1
0
        public LinkedNode2Way <T> AppendNext(LinkedNode2Way <T> node)
        {
            if (node == null)
            {
                return(this);
            }

            Next          = node;
            node.Previous = this;
            return(node);
        }
Ejemplo n.º 2
0
        public LinkedNode2Way(T value, LinkedNode2Way <T> previous = null, LinkedNode2Way <T> next = null)
        {
            Value    = value;
            Previous = previous;
            Next     = next;

            if (previous != null)
            {
                previous.Next = this;
            }
            if (next != null)
            {
                next.Previous = this;
            }
        }
        public static LinkedNode2Way <T> BuildLinkedList2Way <T>(T[] nodeValues)
            where T : IComparable <T>
        {
            if (nodeValues == null)
            {
                return(null);
            }
            if (nodeValues.Length == 0)
            {
                return(null);
            }

            var root    = new LinkedNode2Way <T>(nodeValues[0]);
            var current = root;

            for (int i = 1; i < nodeValues.Length; i++)
            {
                current = current.AppendNext(new LinkedNode2Way <T>(nodeValues[i]));
            }

            return(root);
        }