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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:11:09+00:00 2026-06-13T23:11:09+00:00

In this piece of code I am showing all File object stored in linked

  • 0

In this piece of code I am showing all File object stored in linked list. I am running this in recursive way which let me to explore the entire binary tree.

My job is to count on which level of the tree does each File object is located.

How to do this by using recursion? I was thinking of just counting variable inside, but then I don’t know where to subtract the value if level goes down.

Any ideas?

public void display(T node)
{
    Node temp = node;

    if (temp != null)
    {
        display(temp.left);
        display(temp.right);
    }
}
  • 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-06-13T23:11:10+00:00Added an answer on June 13, 2026 at 11:11 pm

    Increment the level at the begining of the function and decrement it at the end, just before the last line

    private static int level = 0;    
    public void displayFiles(T node)
    {
        Node temp = node;
    
        if (temp != null && temp.leftChild != null && temp.rightChild != null)
        {
         ++level;
            displayFiles(temp.leftChild);
            displayFiles(temp.rightChild);
        }
        --level;
    }
    

    We will increment the level when it enters a new node and decrements it when it leaves the current node and goes to its predecessor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this piece of code : public static void writeFile(File file,List buffer)throws IOException{ File
This piece of code is supposed to go through a list and preform some
I have the following piece of code which is not working the way I
why is this piece of code showing a leak in the Leaks program? btnFaceBook
I have used this piece of code for connecting to the database..It is showing
This piece of code doesn't work; it's logging in into website which is using
This piece of code compiles file in VC6 but in VS 2008 it gives
This is a sample piece of code showing the problem. I need to use
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
This piece of code is from Adobe docs : package { import flash.display.Loader; import

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.