Esempio n. 1
0
    //BFS; find the shallowest node whose text matches that of the specified text.
    public StoryNode Find(string text)
    {
        if (Regex.Matches(this.text, text, RegexOptions.IgnoreCase).Count > 0)
        {
            return(this);
        }
        Queue <StoryNode> toVisit = new Queue <StoryNode> ();

        foreach (StoryNode child in GetChildren())
        {
            toVisit.Enqueue(child);
        }
        while (toVisit.Count > 0)
        {
            StoryNode next = toVisit.Dequeue();
            if (Regex.Matches(next.text, text, RegexOptions.IgnoreCase).Count > 0)
            {
                return(next);
            }
            foreach (StoryNode grandChild in next.GetChildren())
            {
                toVisit.Enqueue(grandChild);
            }
        }

        return(null);
    }