tag:blogger.com,1999:blog-694855878384792308.post4191101950709345169..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to implement Merge Sort Algorithm in Java [Solved] - Example Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-694855878384792308.post-2152658918649757222022-03-12T17:06:21.604-08:002022-03-12T17:06:21.604-08:00The if statement will run only once, but what if t...The if statement will run only once, but what if there are multiple elements left in any of the arrays? <br />To process all the left-out elements while loops are used.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-74526747121541822772021-05-19T10:50:09.133-07:002021-05-19T10:50:09.133-07:00Hi,
I am learning java as a hobby now.
in mergesor...Hi,<br />I am learning java as a hobby now.<br />in mergesort method, this 2 while loops <br /><br />while (first <= mid) { tmp[i++] = input[first++]; } <br /><br />while (last <= end) { tmp[i++] = input[last++]; }<br /><br />I know this two loops check the LAST element left out after the first WHILE loops. because we <br />always divides our array (and sub arrays) into 2 halves. Should it be 2 IF statements? I know <br />it doesn't make anything different but it makes a little more sense to me (in my opinion). I just<br />try not to use loops whenever it can be avoid. Am I missing something here?Anonymoushttps://www.blogger.com/profile/05479635614779651693noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-91385890688246242592020-02-01T06:35:26.248-08:002020-02-01T06:35:26.248-08:00Yes, merge sort is stable sort and you are right &...Yes, merge sort is stable sort and you are right <= should be the right code. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-27766014733190789852020-01-31T20:48:35.443-08:002020-01-31T20:48:35.443-08:00Hi, great post. I am a little confused by one thin...Hi, great post. I am a little confused by one thing. Why is the line:<br /> tmp[i++] = input[first] < input[last] ? input[first++] : input[last++];<br />doesn't use: input[first] <= input[last]<br />I thought merge sort was stable and this seems like it would violate that principle. Am I missing something?<br />BrianUhttps://www.blogger.com/profile/01885117889187226507noreply@blogger.com