Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:54:49+00:00 2026-05-28T19:54:49+00:00

I’m trying to do a linear order traversal on a binary tree but having

  • 0

I’m trying to do a linear order traversal on a binary tree but having trouble getting the correct output. Basically I have created a queue and start by enqueuing the root, then until the queue is empty I dequeue the first element and add its children to the end of the queue. When dequeuing it returns a generic element (). I have a problem in converting this element to a tree node so that I can enqueue its children to the end of the queue in the next step. Here’s what I have done so far:

public void levelOrderTraversal()
{
    NodeQueue<E> queue = new NodeQueue<E>();
    BTPosition<E> current = root;
    queue.enqueue(current.element());
    E temp = null;

    while(!queue.isEmpty())
    {
        temp = queue.dequeue();
        System.out.println(temp.toString());
        current.setElement(temp);

        if (hasLeft(current))
        {
            queue.enqueue(left(current).element());
        }
        if (hasRight(current))
        {
            queue.enqueue(right(current).element());
        }
    }
}

API for BTPosition and NodeQueue can be found in http://net3.datastructures.net/doc4/index.html?net/datastructures/

Any suggestions are really appreciated..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:54:51+00:00Added an answer on May 28, 2026 at 7:54 pm

    You’ll want the Queue to be of type BTPosition<E>. <E> is simply the object type, for instance Integer or String. BTPosition appears to be the actual node in your binary tree.

    public void levelOrderTraversal()
    {
        NodeQueue<BTPosition<E>> queue = new NodeQueue<BTPosition<E>>(); 
        BTPosition<E> current = root;
        queue.enqueue(current); 
    
        while(!queue.isEmpty())
        {
            current = queue.dequeue();
            System.out.println(temp.element().toString());
    
            if (current.getLeft() != null)
            {
                queue.enqueue(current.getLeft());
            }
            if (current.getRight() != null)
            {
                queue.enqueue(current.getRight());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.