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

  • Home
  • SEARCH
  • 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 6709413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:52:43+00:00 2026-05-26T07:52:43+00:00

well i was creating a binary search tree using this code..as far as i

  • 0

well i was creating a binary search tree using this code..as far as i as see using this code i find it to be correct but some how its creating error i dont know why

#include<stdio.h>
#include<conio.h>
#include<malloc.h>

typedef struct node
{  
    struct node *left;  
    int ele;  
    struct node *right;
}*NODE;

void ins(int x,NODE root )
{
    NODE temp;
    //printf("%d    %d*****%d---%d\n",root->ele,root,(root->left),(root->right));   if    i uncomment this line and then (when this function takes first root as its argument )do trace over using turbo C++ compiler its giving me root->left value not null how ever it just executes the next if statement..this should have happened
    if(x<(root->ele) && (root->left)==NULL)
    {
        temp=(NODE)malloc(sizeof(NODE));
        temp->ele=x;
        temp->left=NULL;
        temp->right=NULL;
        root->left=temp;
    }
    else if(x<root->ele && (root->left)!=NULL)
    {
        ins(x,root->left);
    }

    else if(x>(root->ele) && (root->right)==NULL)
    {
        temp=(NODE)malloc(sizeof(NODE));
        temp->ele=x;
        temp->left=NULL;
        temp->right=NULL;
        root->right=temp;
    }
    else if(x>(root->ele) && (root->right)!=NULL)
    {
        //printf("%d***%d***%d",root->ele,root->right->ele) ;
        ins(x,root->right);
    }
    //printf("%d",x);
}

void intrav(NODE root)
{
    if(root->left!=NULL)
        intrav(root->left);

    printf("%d",root->ele);

    if(root->right!=NULL)
        intrav(root->right);
}


void main()
{
    int no,i,elem[50];
    NODE root=NULL;
    printf("enter the no of elements you want to enter\n");
    scanf("%d",&no);
    for(i=0;i<no;i++)
        scanf("%d",&elem[i]);

    root=(NODE)malloc(sizeof(NODE));
    root->ele=elem[0];
    root->left=NULL;
    root->right=NULL;
    //printf("%d---",root);
    for(i=1;i<no;i++)
        ins(elem[i],root);
    //               printf("%d",root->left);

    intrav(root);
    getch();
}

using for loop the ins function is executed every time that takes an array value every time and send it to the function…then if the value to be added

  • 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-26T07:52:44+00:00Added an answer on May 26, 2026 at 7:52 am

    The problem is on the two mallocs, but I think that this is a homework, so I will not tell you exactly what it is.

    HINT: Check what type NODE is!

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

Sidebar

Related Questions

I'm creating a sitemap in XML, it works well with one record displayed, but
I'm creating a plot in matlab that includes some lines, as well as a
I'm creating some KML files on a web site and everything works well in
I am creating a Boggle clone game and it works very well so far.
I'm creating a reverse HTTP proxy using Node.js for fun. The code is pretty
I have a script working well for creating ad hoc iPhone builds. I can
Is there a well maintained package available in Python for creating and validating HTML
I've been mulling over creating a language that would be extremely well suited to
I am creating site with php. On localhost all works well. On my hosting
Does anybody know of a reliable, well-made tool for creating standalone desktop applications complete

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.