Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Recursion question

  • 18-04-2012 06:02PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Yes.


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 5,015 ✭✭✭Ludo


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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,062 ✭✭✭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, Registered Users 2 Posts: 1,645 ✭✭✭k.p.h


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

    Ah I see :p


Advertisement