[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

05/20/2006 at 08:28PM PDT, ID: 21858164
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Need help in resolving an error in the attached code

Asked by swtirs in C Programming Language

Tags: assignment, pointer, in_order

When the below code is executed, it gives an error in the statement below statement.
T=Binary_Tree(list, 0, number);

The error says.
"Non portable pointer assignment in function main". I am using TurboC on win32.




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

/* -------------------------------------------------------  */
/* Definitions */

struct node
{
      char info;
      struct node *left_child;
      struct node *right_child;

};

struct node *binary_tree(char *, int, int);
void output(struct node*, int);
void pre_order(struct node*);
void in_order(struct node*);


/* -------------------------------------------------------  */
/* Function to create an binary tree */

struct node * binary_tree (char * list, int lower, int upper)
{
      struct node * node;
      int mid=(lower+upper)/2;

node=(struct node*)malloc(sizeof(struct node));
node->info=list [mid];

if(lower>=upper)
{
      node->left_child=NULL;
      node->right_child=NULL;
      return(node);

}
if(lower<=mid-1)
      node->left_child=binary_tree(list,lower,mid-1);
else
      node->left_child=NULL;
if(mid+1<=upper)
      node->right_child=binary_tree(list,mid+1,upper);
else
      node->right_child=NULL;
      return(node);
}


/* -------------------------------------------------------  */
/* output Function */

void output(struct node *T, int level)
{
      int i;
      if(T)
      {
            output(T->right_child, level+1);
            printf("\n");
            for(i=0;i<level;i++)
                  printf("    ");

            printf(" %c", T->info);
            output(T->left_child,level+1);
      }
}


/* ------------------------------------------------------- */
/* Pre_order Traversal */

void pre_order (struct node *node)
{
      if(node)
      {
            printf("%c", node->info);
            pre_order (node->right_child);
            pre_order(node->right_child);
      }
}


/* ------------------------------------------------------- */
/* In_order traversal */

void in_order(struct node *node)
{
      if(node)
      {
            in_order(node->left_child);
            printf("%c",node->info);
            in_order(node->right_child);
      }
}


/* ------------------------------------------------------- */
/* The entry point - Main */

void main()
{
      char list[100];
      int number = 0;
      char info;
      char choice;
      struct node *T=(struct node*)malloc(sizeof(struct node));
      T=NULL;
      printf("\n Input choice 'b' to break:");
      choice=getchar();
      fflush(stdin);
      while(choice!='b')
      {
            printf("\n Input information of the node:");
            scanf("%c", &info);
            list[number++] = info;
            fflush(stdin);
            printf("\n Input choice 'b' to break:");
            choice=getchar();
            fflush(stdin);
      }
      number--;
      printf("\n number of elements in the list is %d", number);
      T=Binary_Tree(list, 0, number);
      output(T,1);
      printf("\n pre_order traversal\n');
      pre_order(T);
      printf("\n In_order traversal \n");
      in_order(T);
[+][-]05/20/06 08:33 PM, ID: 16726676

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: assignment, pointer, in_order
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05/20/06 08:38 PM, ID: 16726685

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74