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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:56:09+00:00 2026-05-26T06:56:09+00:00

I had an interview and I could not answer this question. You have an

  • 0

I had an interview and I could not answer this question. You have an binary tree and you are putting all the nodes into an array using in_order and you return the value for the size of the array. I was told that I could not use a helper function and add int i=0 for an array counter.

The recursive function heading I had to use was.

      In_order(Struct_Node * node, int *array){

      }

Because it was In_order I wrote.

      if(node){
      In_order(node->left, array);

//this line is where I am supposed to add the elements and return the value,
but I do not understand how to do this. This is my week point and I need to understand
the reasoning of how this code works more than what is the code.

      in_order(node->right,array); 
      }

I didn’t actually write what I wrote in between the two In_order statements but what I wrote was wrong.

  • 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-26T06:56:09+00:00Added an answer on May 26, 2026 at 6:56 am

    Guessing all the missing details I think you would do something like:

    int In_order(Struct_Node * node, int *array){
    
       int count = 0;
       if (node->left) {
         count += In_order(node->left, array);
       }
       array[count++] = node->data; // whatever it is you're storing
       if (node->right) {
         count += In_order(node->right, array+count);
       }
       return count;
    }
    

    The key point is you pass an updated pointer to the RHS recursive call and your return value is 1 + LHS return + RHS return

    If you can’t use an int as a counter (which is silly really because it’s by far the clearest way of expressing it) you can do:

    int In_order(Struct_Node * node, const int *array){
       int *tptr = array;
    
       if (node->left) {
         tptr += In_order(node->left, array);
       }
       *tptr++ = node->data; // whatever it is you're storing
       if (node->right) {
         tptr += In_order(node->right, tptr);
       }
    
       return tptr-array;
    }
    

    If you wanted to go “a little” crazy and avoid any locals other than the function arguments you could change the return type to be a pointer to the current working end of the array (which is in effect the size of the array also) and do:

    int *In_order(const Struct_Node * const node, int * const result) {
      return !node ? result :
              In_order(node->right, &(*In_order(node->left, result) = node->value)+1);
    }
    

    Although to be quite honest that’s terrible code (I’m not even 100% sure that it is well defined!) and I really hope they weren’t looking for a solution like that!

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

Sidebar

Related Questions

I encountered this question in an interview and had no clue how to answer:
Yesterday i had a question in an interview which i thought i could find
I had an interview days ago and was thrown a question like this. Q:
I just got this question on an interview and had no idea how to
Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis)
I had an interview today and the person asked me this question: How do
I was asked this question in an interview and had no idea. And I
I had this question: Given an unsorted array of positive integers and an integer
I had an interview question asking this: text file has following lines> 1: A
Had this question in an interview.

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.