can any one help me to how to create avl tree of strings in c

Recommended Answers

All 11 Replies

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.

Do you know function in C to compare two strings?

ya i know how to compair strings..
avl for mon,tue wed, is

mon
tue
wed

after rotation

tue

mon wed


am i right???
cau u help what is b* tree

ya i know how to compair strings..
avl for mon,tue wed, is

mon
tue
wed

after rotation

tue

mon wed


am i right???
cau u help what is b* tree

Yes. However if you put that in code blocks, the indentation and spaces will be preserved so we can read it better. Ie,

mon
                tue
                   wed    

after rotation

                tue

            mon       wed

cau u help what is b* tree

Sure we're here to help.. :icon_evil:

  1. If you're using a decent web browser, this is how you find out what is b* tree:
  2. Left click (and hold) just before "what"
  3. Now drag your mouse to the right until you have selected the "is" and "b*" and "tree" as well.
  4. Leave the left button.
  5. Now right click in the middle of the selected text.
  6. In the menu that you see, look for the word Google or Yahoo or Search and click on it.
  7. A new web-page should open up with answers !!
    PS: Of course you'll have to read it.

Amazing isn't it?!

PS:
1. This amazing method is known as RTFW.
2. In case you're not using a "decent browser" then get back and I would tell you an alternate way.

Sure we're here to help.. :icon_evil:

  1. If you're using a decent web browser, this is how you find out what is b* tree:
  2. Left click (and hold) just before "what"
  3. Now drag your mouse to the right until you have selected the "is" and "b*" and "tree" as well.
  4. Leave the left button.
  5. Now right click in the middle of the selected text.
  6. In the menu that you see, look for the word Google or Yahoo or Search and click on it.
  7. A new web-page should open up with answers !!
    PS: Of course you'll have to read it.

Amazing isn't it?!

PS:
1. This amazing method is known as RTFW.
2. In case you're not using a "decent browser" then get back and I would tell you an alternate way.

Or do the same thing with "what is avl tree"... :-)

@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 "

Int
                Char               Struct
            Case        Double                 While
        Break        Const    Float

is this right???

I'm having trouble nailing down what your problem is. Are you having trouble with creating an AVL tree, or is the issue using string keys for a working AVL implementation?

Well, that would be an unbalanced tree. A more balanced one would look like this:

Int
                Char              Float
            Case    Const   Double     Struct
       Break                                 While

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.