Пример #1
0
        private bool MergePaths(LinkedList <GraphNode <T> > eularianPath, List <GraphNode <T> > partialPath, GraphNode <T> startNode)
        {
            if (startNode == null)
            {
                return(true);
            }
            if (eularianPath.Count == 0)
            {
                foreach (var node in partialPath)
                {
                    eularianPath.AddLast(node);
                }

                return(true);
            }

            var mergeNode = eularianPath.FindLast(startNode);

            if (mergeNode == null)
            {
                return(false);                   // unable to merge
            }
            for (var i = 1; i < partialPath.Count && mergeNode != null; i++)
            {
                var node = partialPath[i];
                eularianPath.AddAfter(mergeNode, new LinkedListNode <GraphNode <T> >(node));
                mergeNode = mergeNode.Next;
            }

            return(true);
        }