Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Recursion question

Options
  • 18-04-2012 6:02pm
    #1
    Registered Users Posts: 1,645 ✭✭✭


    Probably a simple question, would this method be described as a recursive method.?

    It's just a sorting method for a heap I am doing in college. For some reason I am hesitant to say it is even though it obviously calls itself within the code. Feels slightly different from the other recursive functions I would have looked at like Fibonacci and Factorial.
       private void bubbleUp(int index ) {
            if( index > 0 ) {
                int parentNode = ( index - 1 ) / 2;
                if( array[ parentNode ] > array[ index ] ) {
                    swap( parentNode, index );
                    bubbleUp( parentNode );
                }
            }
        }
    


Comments

  • Registered Users Posts: 7,157 ✭✭✭srsly78


    Yes.


  • Registered Users Posts: 1,645 ✭✭✭k.p.h


    Thanks, so the definition of a recursive function is just a function that calls itself. That simple ..?


  • Registered Users Posts: 5,015 ✭✭✭Ludo


    Google "recursion"...silly software engineering humour :-)


  • Registered Users Posts: 1,645 ✭✭✭k.p.h


    Yeah I'v done the google ;) quite a bit about recursion online,lot of different types and a broad subject IMO. What I was wondering about was it incorrect to refer to any method that calls itself under the term "recursion" in exam situations etc. Seems like it's OK anyway. Thanks for the help.


  • Registered Users Posts: 2,022 ✭✭✭Colonel Panic


    And the most common use of recursion is the type you're not used to! Using it to walk data structures on the other hand is common as hell!


  • Advertisement
  • Registered Users Posts: 1,645 ✭✭✭k.p.h


    Ludo wrote: »
    Google "recursion"...silly software engineering humour :-)

    Ah I see :p


Advertisement