Sorry, but we aren't going to do your homework for you. Please make an effort to solve this problem first, even if it is only a text description of what you think you should do. There are a lot of texts on this subject, and plenty of those to be found on the internet as well. Try googling for "AVL tree".
thanks guys but i want to constuct an avl tree for strings e.g. mon,tue,the,wed,thu,fri,sat,sun.
i know for integers like left child is <root and right child is >root but wat abt strings n need code for that.....
@Junior Poster not geetting anything related to string avl on net...
It would help if you don't differentiate between int and string in this case. Try to think of an AVL tree as a tree consisting of "nodes". Each node represents some item. All items in teh tree are of the same type. Be it int or long or string or ...
When you insert an item into the tree, first thing you need to do is find the correct location for it. To do this what you need is "ability to compare" item you're inserting with the items already in the tree.
When you're dealing with ints C already provides you with this ability (operators ==, >, <,...). But when the items in your tree are strings you need to use something else that can compare 2 strings and tell you which is "greater/less-than than" the other.
So to simplify, the only differences between an int AVL tree and string AVL tree are:
1. Type of the node elements.
2. What you use for comparing the node elements.
@thekashyap ----thanksssssssssss but i have tried bt not geetting what i want....
@rubberman thanks but the problem is with double rotation
eg is "create avl tree of
Double ,int ,struct , while , break , case, char, float, const "
Case Double While
Break Const Float
Well, that would be an unbalanced tree. A more balanced one would look like this:
Case Const Double Struct
The main thing about AVL tress is that no sub-tree can be more than one level deeper than its sibling. While yours is technically that, it may no exhibit a self-balancing state if you were to insert new elements. Then again, it might. I've written these in commercial code in the deep dark past for database indexing applications, but you haven't included any of your code to analyze for correctness.