DZone
IoT Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > IoT Zone > Breadth First Search - C#

Breadth First Search - C#

Aniruddha Deshpande user avatar by
Aniruddha Deshpande
·
Jun. 01, 12 · IoT Zone · Code Snippet
Like (0)
Save
Tweet
12.73K Views

Join the DZone community and get the full member experience.

Join For Free

Breadth First Search using C#

class BinaryTreeNode
        {
            public BinaryTreeNode Left { get; set; }

            public BinaryTreeNode Right { get; set; }

            public int Data { get; set; }
        }


        public class BreadthFirstSearch
        {
            private Queue _searchQueue;
            private BinaryTreeNode _root;

            public BreadthFirstSearch(BinaryTreeNode rootNode)
            {
                _searchQueue = new Queue();
                _root = rootNode;
            }

            public bool Search(int data)
            {
                BinaryTreeNode _current = _root;
                _searchQueue.Enqueue(_root);

                while (_searchQueue.Count != 0)
                {
                    _current = _searchQueue.Dequeue();
                    if (__current.Data == data)
                    {
                        return true;
                    }
                    else
                    {
                        _searchQueue.Enqueue(_current.Left);
                        _searchQueue.Enqueue(_current.Right);
                    }
                }

                return false;
            }
        }

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Guide to Events in Vue
  • Data Visualization of Healthcare Expenses by Country Using Web Scraping in Python
  • Instancio: Random Test Data Generator for Java (Part 1)
  • A Guide to Understanding Vue Lifecycle Hooks

Comments

IoT Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo