ошибка CS0246: не удалось найти тип или имя пространства имен «Узел» (отсутствует директива using или ссылка на сборку?) - PullRequest
0 голосов
/ 25 апреля 2020

по какой-то причине компилятор не распознает мой класс Node, хотя у меня все они в одном пространстве имен: / Сообщение об ошибке в заголовке ссылается на эту строку static Node sampleTree()

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bfs_and_dfs;

namespace bfs_and_dfs
{
    partial class Program
    {
        static Node sampleTree()
        {
            Node root = new Node("A", 
            new Node("B", new Node("C"), new Node("D")),
            new Node("E",
                new Node("F"), new Node("G", new Node("H"), null))
            );

            return root;
        }

        static void Main(string[] args)
        {
            Node tree = sampleTree(); bfs_traversal(tree);
        }
    }
}

Node.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bfs_and_dfs
{
    public class Node
    {
        public Node left;
        public Node right;
        public string data;

        // For non-leaf nodes
        public Node(string data, Node left, Node right)
        {
            this.data = data;
            this.left = left;
            this.right = right;
        }

        // For leaf nodes
        public Node(string data)
        {
            this.data = data;
            this.left = null;
            this.right = null;
        }
    }
}

BFS_traversal.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bfs_and_dfs
{
    partial class Program
    {
        const int ALPHABET_SIZE = 26;
        const int A_ASCII = 65;

        static void bfs_traversal(Node startNode)
        {
            // dangerously assumes all nodes contain
            // one of 26 letters in the alphabet
            bool [] visited = new bool[ALPHABET_SIZE];
            // Array.Fill(visited, false);

            Queue<Node> q = new Queue<Node>();
            q.Enqueue(startNode);
            visited[char.Parse(startNode.data.ToUpper()) - A_ASCII] = true;

            while (q.Count > 0)
            {
                Node node = q.Dequeue();
                System.Console.Write(node.data + " ");

                if (node.left != null 
                && !visited[char.Parse(node.left.data.ToUpper()) - A_ASCII])
                {
                    q.Enqueue(node.left);
                    visited[char.Parse(node.left.data.ToUpper()) - A_ASCII] = true;
                }

                if (node.right != null
                && !visited[char.Parse(node.right.data.ToUpper()) - A_ASCII])
                {
                    q.Enqueue(node.right);
                    visited[char.Parse(node.right.data.ToUpper()) - A_ASCII] = true;
                }
            }
            System.Console.WriteLine();
        }
    }
}

Любая помощь приветствуется. В качестве текстового редактора я использую код Visual Studio.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...