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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:35:15+00:00 2026-06-15T09:35:15+00:00

This is a question I thought it would be easy but I found I’m

  • 0

This is a question I thought it would be easy but I found I’m wrong in the last. I can finish the program without recursive but I want to ask whether this problem can be finished in recursive version or not?

  • 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-15T09:35:17+00:00Added an answer on June 15, 2026 at 9:35 am

    A recursive binary search tree traversal is basically (pseudo-code in case this is coursework):

    def traverse (node):
        if (node == NULL):
            return
        traverse (node.left)
        doSomethingWith (node.payload)
        traverse (node.right)
    :
    traverse (root)
    

    That’s all there is to it really, just replace doSomethingWith() with whatever you want to do (such as print).

    That will traverse in left to right order so, if your BST is ordered in such a way that left means lower, simply swap over the two traverse calls.

    By way of example, consider the following tree:

           20
          /  \
        10    25
       /     /  \
      5    24    27
     /          /
    2         28
    

    as embodied in this example C program:

    #include <stdio.h>
    
    typedef struct s {
        int payload;
        int left;
        int right;
    } tNode;
    
    tNode node[] = {  // Trust me, this is the tree from above :-)
        {20,  1,  4}, {10,  2, -1}, { 5,  3, -1}, { 2, -1, -1},
        {25,  5,  6}, {24, -1, -1}, {27, -1,  7}, {28, -1, -1}};
    
    static void traverse (int idx) {
        if (idx == -1) return;
        traverse (node[idx].right);
        printf ("%d ", node[idx].payload);
        traverse (node[idx].left);
    }
    
    int main (void) {
        traverse (0);
        putchar ('\n');
        return 0;
    }
    

    Running that program gives you the following output:

    28 27 25 24 20 10 5 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this question would have already existed on SO, but then I couldn't
I thought I would post this here not so much as a question but
this follows on from my last question which I thought was answered but for
I thought I would rewrite this question (same iteration). The original was how to
This is similar to this question , but I thought I'd reword it a
This post asks this question but doesn't really give an answer, so I thought
I thought this must be easy but I really have troubles figuring it out:
I started experimenting with C# and HTML5 today. I thought this question would be
I read some of the discussion in this question and thought to myself that
I ran into this question today and thought I should post it for the

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.