Пример #1
0
        private static void AllPaths(LinkedList <GraphNode <char> > path, List <List <char> > allPaths)
        {
            GraphNode <char> curr = path.Last();

            bool deadEnd = true;

            foreach (GraphNode <char> neighbor in curr.Neighbors)
            {
                if (!path.Contains(neighbor))
                {
                    deadEnd = false;

                    path.AddLast(neighbor);
                    GraphSearch.AllPaths(path, allPaths);
                    path.RemoveLast();
                }
            }

            if (deadEnd)
            {
                List <char> charPath = new List <char>();

                foreach (GraphNode <char> node in path)
                {
                    charPath.Add(node.Value);
                }

                allPaths.Add(charPath);
            }
        }
Пример #2
0
        public static List <List <char> > AllPaths(GraphNode <char> node)
        {
            List <List <char> >            allPaths = new List <List <char> >();
            LinkedList <GraphNode <char> > path     = new LinkedList <GraphNode <char> >();

            path.AddLast(node);
            GraphSearch.AllPaths(path, allPaths);
            return(allPaths);
        }