Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Incorrect Output in Merge Sort  RSS feed

 
dhrubo bhattacharjee
Greenhorn
Posts: 20
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello , I am trying to learn datastructures and algorithms .I was trying to implement MergeSort. Following is the code that I have written:




But However I am getting the wrong output after running this code.Following is the output that I am getting :





I cannot figure out where am I going wrong.Can anyone please look into this and let me know which part of the logic here is wrong.

Thank you.
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using the wrong index when you compare the two values in the merge function.
 
dhrubo bhattacharjee
Greenhorn
Posts: 20
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:You are using the wrong index when you compare the two values in the merge function.



Thanks a lot.Yes it was silly mistake on my behalf.It is working fine when I change the code from :


to :

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