-3

Sorry for the bad title and if i mislead anyone.

I am new to Binary Trees, so it's a bit hard for me to explain this. Let's say that i need to create a BST in which each node holds different kinds of info (e.g. name, occupation, salary) and it is to be ordered based on the salary. Is that possible? If it is, give me a few instructions. If it isn't, could you please explain a bit why that is?

Thanks in advance.

Schizoed
  • 1
  • 1
  • It is possible, read http://www.geeksforgeeks.org/comparator-function-of-qsort-in-c/ and this excellent answer: http://stackoverflow.com/a/10406289/2204926 – Idos Jun 05 '16 at 11:50
  • Yes it's possible. What research have you done? What code have you written? – nicomp Jun 05 '16 at 11:50
  • It makes no sense that each node in a BST contains *different* kinds of information. Each node should contain the same *kind* of information, for example a structure. – Some programmer dude Jun 05 '16 at 11:51
  • Idos, thanks for the info (that actually kinda helps). nicomp, i haven't written any code yet, since i was trying to understand better what i want to do and i did a 15 minute research i guess but it wasn't really helpful and i wanted a quick answer due to time restriction (thanks for your answer). Joachim Pileborg, yea i understand what you are saying and it was my mistake in the description (thanks for your info though). – Schizoed Jun 05 '16 at 12:01

1 Answers1

0

Yes its possible. You will have to create a struct having 3 data members like this:

struct node
{
     char name[20];
     char occupation[20];
     long salary;
     struct node *left_child;
     struct node *right_child;
};

and then you can perform the operations of insertion and deletion wrt the salary keeping in mind that lesser salary nodes will be on the left and higher salary on the right. Also you'll need a root node pointer as well.

riteshtch
  • 8,629
  • 4
  • 25
  • 38