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 6628093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:05:26+00:00 2026-05-25T22:05:26+00:00

I’m wondering if its possible to have an inorder tree traversal method in java

  • 0

I’m wondering if its possible to have an inorder tree traversal method in java actually RETURN something… I’m trying to traverse through the tree given a node and a value, return the node that matches the value:

/**
 * Variable for storing found node from inorder search
 */
private Node returnNode; 


/**
 * Perform an inorder search through tree.
 * If a value is matched, the node is saved to returnNode, otherwise return null.
 * @param node The given node
 * @param value The value of the node to be found.
 */
public void inorder(Node node, Object value){
    if(node != null){
        inorder(node.leftChild, value);
        if(node.value.equals(value)){
            System.out.println(value + " was found at " + node);
            returnNode = node;
        }
        inorder(node.rightChild, value);
    }
}

Right now, I’ve tried declaring a public node to store the value, but I find that that doesn’t work when I run:

assertEquals(newNode3, BT.contains("3"));
assertEquals(null, BT.contains("abcd"));

Where returnNode takes on newNode3’s values and messes up my tests for null.

Can anyone point me in the right direction?

  • 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-25T22:05:27+00:00Added an answer on May 25, 2026 at 10:05 pm

    I would have thought you’d want something like this:

    /**
     * Perform an inorder search through tree.
     * The first node in order that matches the value is returned, otherwise return null.
     * @param node The given node
     * @param value The value of the node to be found.
     * @return The first node that matches the value, or null
     */
    public Node inorder(Node node, Object value){
        Node result = null;
        if(node != null){
            result = inorder(node.leftChild, value);
            if( result != null) return result;
    
            if(node.value.equals(value)){
                System.out.println(value + " was found at " + node);
                return node;
            }
            result = inorder(node.rightChild, value);
        }
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
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.