Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Binary tree question

Binary tree question

Scheduled Pinned Locked Moved ATL / WTL / STL
questiondata-structurestutorial
13 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S sadas232341s

    what is max

    B Offline
    B Offline
    barneyman
    wrote on last edited by
    #4

    sorry

    #define max(a,b) a>b?a:b

    S 1 Reply Last reply
    0
    • S sadas232341s

      what is max

      S Offline
      S Offline
      sadas232341s
      wrote on last edited by
      #5

      And how to call the function? I mean what has to be the second argument innerDepth. I call it with the tree and the Height as second argument and it gives me 4, 3, 1 as output. I need only 4.

      B 1 Reply Last reply
      0
      • B barneyman

        sorry

        #define max(a,b) a>b?a:b

        S Offline
        S Offline
        sadas232341s
        wrote on last edited by
        #6

        Yes I define my own Max function, but why the output is 4,3,1 and not only 4?

        B 1 Reply Last reply
        0
        • S sadas232341s

          Yes I define my own Max function, but why the output is 4,3,1 and not only 4?

          B Offline
          B Offline
          barneyman
          wrote on last edited by
          #7

          i think the return should be

          // and return the depth this node represents
          return currentDepth+(maxDepth,rightdepth);
          
          S 1 Reply Last reply
          0
          • S sadas232341s

            And how to call the function? I mean what has to be the second argument innerDepth. I call it with the tree and the Height as second argument and it gives me 4, 3, 1 as output. I need only 4.

            B Offline
            B Offline
            barneyman
            wrote on last edited by
            #8

            call it with

            OnlyLeafNodes(rootNode,0);

            1 Reply Last reply
            0
            • B barneyman

              i think the return should be

              // and return the depth this node represents
              return currentDepth+(maxDepth,rightdepth);
              
              S Offline
              S Offline
              sadas232341s
              wrote on last edited by
              #9

              maxDepth is? and why is it in brackets? Is it a function or something? i don' t know

              S B 2 Replies Last reply
              0
              • S sadas232341s

                maxDepth is? and why is it in brackets? Is it a function or something? i don' t know

                S Offline
                S Offline
                sadas232341s
                wrote on last edited by
                #10

                OK I think I did it it has to be

                return currentDepth - leftDepth + rightDepth;

                S 1 Reply Last reply
                0
                • S sadas232341s

                  OK I think I did it it has to be

                  return currentDepth - leftDepth + rightDepth;

                  S Offline
                  S Offline
                  sadas232341s
                  wrote on last edited by
                  #11

                  Now If you can explain me how the whole function works...

                  B 1 Reply Last reply
                  0
                  • S sadas232341s

                    maxDepth is? and why is it in brackets? Is it a function or something? i don' t know

                    B Offline
                    B Offline
                    barneyman
                    wrote on last edited by
                    #12

                    // and return the depth this node represents
                    return currentDepth+max(leftDepth,rightdepth)

                    1 Reply Last reply
                    0
                    • S sadas232341s

                      Now If you can explain me how the whole function works...

                      B Offline
                      B Offline
                      barneyman
                      wrote on last edited by
                      #13

                      it works by only printing those nodes who have only one depth below them, no more

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups