# Thread: Converting From Binary Tree to Threaded Binary Trees

1. ## Converting From Binary Tree to Threaded Binary Trees

Hello,
I'm having trouble in Converting From Binary Tree to Threaded Binary Trees.
Please could you help me writing a function that can make the conversion.

2. What exactly are you trying to run in parallel?

gg

3. Originally Posted by Codeplug
What exactly are you trying to run in parallel?
No, it has nothing to do with multiple threads. A threaded-tree is a modified binary tree data structure allowing faster travelling between nodes.
It's kind of a binary tree and linked-list all in one data structure. See here:

5. Originally Posted by elton_fan
I think the pointer by iMalc should get you on the right path. I also got plenty of hits from google by entering "Threaded Binary Tree implementation"

What exactly do you want us to do? Write a function that takes some arbitrary C code and adds a "thread pointer" [either as a separate pointer or using the left/right nodes that should be NULL as backpointers] - that is a MAJOR task that would take a very experienced C parser writer quite some time to develop. I'm not experienced in writing C parsers, but I understand this problem enough to know that it's non-trivial.

--
Mats

6. This is the best I could do please try to help me

Code:
```#include<stdio.h>
#include<stdlib.h>
typedef struct _x{
int th_left,th_right,num;
struct _x *left,*right;
}node;
node *insert(node *x,int num);
node *convert(node*x);
int
main(void){
node *root;
int number,sentinel;
sentinel=-10;
root=NULL;
printf("Enter a number of -10 to exit\n");
do{
scanf("&#37;d",&number);
if(number!=-10)
root=insert(root,number);
}while(number!=sentinel);
root=convert(root);
return(0);
}
node
*insert(node *x,int num){
if(x==NULL){
x=(node*)malloc(sizeof(node));
x->num=num;
x->left=NULL;
x->right=NULL;
x->th_right=0;
x->th_left=0;
}
else if(num>x->num)
x->right=insert(x->right,num);
else if(num<x->num)
x->left=insert(x->left,num);
return(x);
}
node
*convert(node*x){
// filling the threads
node *walker;
walker=x;
while(walker->left!=NULL)
walker=walker->left;
walker->th_left=1;
walker=x;
while(walker->right!=NULL)
walker=walker->right;
walker->th_right=1;
// threads are successfully filled

return(x);
}
node
node *temp;
temp=x;
if(x==NULL)
return;
else{
if(!x->th_right){
while(x->right!=NULL)
x=x->right;
x->right=temp;
}
if(!x->th_left){
while(x->left!=NULL)
x=x->left;
x->left=temp;
}
}
free(temp);
}```

7. please try to find out what is the problem with me

8. Have a look at this:
http://www.catb.org/~esr/faqs/smart-....html#explicit

Please feel free to go back to the top and read the rest of the page too!

--
Mats

9. because you couldn't find the solution you're sending me a ........ing website

10. Originally Posted by elton_fan
because you couldn't find the solution you're sending me a ........ing website
No, because I can't be bothered to spend half an hour of my time FIGURING OUT something that you should be able to write down in 5 minutes - namely: a summary of what you are do to test the code, and how it fails!

If you ask the right questions, you will get the right answers. If you can't even be bothered to write a decent question, how do you expect someone to help you?

--
Mats

11. By experience, I know the experienced programmers by the way that they are looking at the code.

12. You can't exactly see his eyes can you?

You can't expect to type a half assed question and expect someone like matsp to see, "ohh he means this" and give you the 'answer'. In fact you didn't even ask a question.

> please try to find out what is the problem with me
That's a question I can answer, http://www.catb.org/~esr/faqs/smart-....html#explicit

13. Originally Posted by elton_fan
please try to find out what is the problem with me
You don't really want to be asking that but...
Well you're English is slightly poor and lacks capital letters and punctuation, you don't ask a specific question (no question mark), and you behave less than nicely towards those who are trying to help you to help yourself.

Now, let me ask you a question, which if you can answer, will enable us to properly help you. Can you describe for us please in your own words how you are trying to solve the problem, and what doesn't work with the code you posted?
(I have studied and implemented a kind of threaded tree before)

14. I have never thought that this forum is one of the few forums which holds the stupidest computer programmers in the world.
I will quite before being attacked by the epidemic which called "stupidity" that you acquired here.

15. by the way you have a very nice page iMalc.
did you use Textpad to created?????

Popular pages Recent additions