• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursion problem  RSS feed

 
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends

in this code

the first recursion is run n time dependent the base condition so ok no problem but after reach to the base case,the merge method invoked !
I expect second recursion invoked instead of merge.

does need more study on recursion concept ? or simply I miss something ?! 
 
Saloon Keeper
Posts: 4038
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's impossible to say what's happening without seeing the full code of the method.
 
Greg Sully
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my bad


need more information ?
is there any edit button ?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Sully wrote:
I expect second recursion invoked instead of merge.


Well, how do you know which recursive call happened? Do you have a debugging message that tells you if it is the first or the second? Or are you simply working out the math indexes?

Also, do you have any (debugging) output to determine the cases where the second recursive call doesn't do anything? meaning where middle2 causes a call that doesn't have anything to sort?

Henry
 
Greg Sully
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, how do you know which recursive call happened? Do you have a debugging message that tells you if it is the first or the second? Or are you simply working out the math indexes?

I know cause the output..no there isnt any debugging message..lemme show you full codes
Here :

the first recursion split the first half array and then merge invoked cause the output show merge mehtod.
my English is not good enough to explain my exact problem nd Im sure my problem is very easy for you guys so
maybe laughing on me

 
Tim Moores
Saloon Keeper
Posts: 4038
94
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A useful debugging addition would be to print out the values of low and high first thing in the sortArray method. That way you'll know for sure whether the if condition would trigger or not.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Sully wrote:
the first recursion split the first half array and then merge invoked cause the output show merge mehtod.


First, you only have two print statements? One for the first sort, and one for the merge? How large is your array? Two elements?

Anyway, as mentioned, by Tim (and me, with an earlier port), put a debugging message prior to the "if" condition. It is entirely possible that you are just not seeing the split message, because the condition is not true.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!