![]() I suspect you made an error when you tried to implement the technique described. In fact, it is a fairly standard technique. It's unfortunate that you had problems with the challenge, but the technique describe in the article is not incorrect. The 1st copy of the function will return (and vanish). The Merge Above Together step will finish. The 2nd copy of the function will return (and vanish). The 1st copy of the function will move on to the next line. ![]() The 2nd copy of the function will move on to the next line. The 3rd copy of the function will return (and vanish). The call to MergeSort() will then generate a 3rd copy of the function The call to MergeSort() will then generate a 2nd copy of the function The 1st copy of the function will be made which looks like this: I'll denote each step that each version of the function is executing with a >. For MergeSort on arrays with = 2 elements the function is: It is probably best illustrated with an example. So, if the currently executing copy of the MergeSort function was called by another copy of the MergeSort function to sort the calling functions left subarray, then after the currently executing version finishes, the version that called it will then move on to its next step, which is to call MergeSort to sort its right subarray. ![]() When one function returns the function that called it continues to execute. When you use recursion, there may be several copies of a function, all at different stages in their execution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |