+ Reply to Thread
Results 1 to 6 of 6

Thread: Binary Tree with linked lists help

  1. #1
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Binary Tree with linked lists help

    Okay so right now I have a program that is running. It makes a tree and each tree has a linked list attached to it.
    The tree is somewhat binary but in a hierarchy form so its not in the correct number order. Basically each node is referred to as a "costcenter" and each costcenter has a linked list which are expenses which has a name and an amount.
    It puts the tree and linked list together right now but im brainstorming on the second output. It outputs one just by adding all expenses up in the list and displaying it by the node - if the nodes is under another node the node above it gets the amount as well. There are lots of ways of doing the second output but im trying to find one where its fast and doesn't require much I was thinking somewhat recursive... either way whats your opinion on the fastest way to do this one? It may require a list just because its in a hierarchy form.

  2. #2
    Learning Programmer ReignInChaos will become famous soon enough ReignInChaos's Avatar
    Join Date
    Feb 2009
    Location
    NJ
    Age
    23
    Posts
    37
    Blog Entries
    5

    Re: Binary Tree with linked lists help

    If you need to traverse all the parent nodes or simply all the nodes in general, a recursive traversal would be the best route for you to take. I am a little unclear exactly what it is that you are trying to do so if you need more help please explain a little more.

  3. #3
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Re: Binary Tree with linked lists help

    Yes I need to transverse all the nodes but then each node of the binary tree had a linked list and I needed to be able to add all the amounts in the linked list to get the total for each node but then each node also counts for all nodes under it.

    I actually figured it out - I might post the code in a bit in the other forum a bit later.

  4. #4
    Newbie micheljaw is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    4

    Re: Binary Tree with linked lists help

    This depends on several things, of course. I'd say that a linked list is right out, since it has few suitable properties to work as a symbol table. A binary tree might work, if you already have one and don't have to spend time writing and debugging it. My choice would be a hash table, I think that is more or less the default for this purpose.
    -----------------------------------------------

  5. #5
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Re: Binary Tree with linked lists help

    Well a hash table wouldnt work well - all the names are in number format - that is the names of the costcenters and the names of the expenses so id have to mod the number and those are really easily going to overlap.

    My binary tree and linked list solution did work - I ended up keeping a few more variables (time vs space) to make it run faster. It keeps an end total of how much the node has "spent" and all the parent nodes also get a copy of the expense.

    I posted the source of this up a few days ago if you guys want to see...

    View Source Code here - CodeCall

  6. #6
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: Binary Tree with linked lists help

    For what you are doing (if I understand it correctly), I would almost made a node class that holds onto the individual values in a list. Then have it hold onto a total sum and have a sum option in it to grab the sum of all the values in that list and update the main sum. This way, you don't end up with a larger runtime than what is required, especially in this tree which will already run in log time for a single lookup.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 8
    Last Post: 12-16-2009, 01:53 PM
  2. Tutorial: Starting C# with C# 2008 Express Edition
    By Jordan in forum CSharp Tutorials
    Replies: 20
    Last Post: 07-27-2009, 04:45 AM
  3. Debugging a C++/C File with GDB Debugger
    By awesome001 in forum C and C++
    Replies: 2
    Last Post: 01-01-2009, 07:07 PM
  4. Help with Square root and calculator program!!!
    By 123456789asdf in forum C and C++
    Replies: 10
    Last Post: 12-02-2007, 04:35 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts