SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Uml And Patterns
Exercise:
Programming Projects
Question:9 | ISBN:9780132830317 | Edition: 5

Question

Use the sorting pattern to implement insertion sort. In insertion sort, the split method always returns the value (end — 1) . This results in splitting the array into two pieces, one with a single value at the end of the array, and the other with everything else. The join method does more work. A precondition for entry into join is that the elements from a[begin] to a[end-1] will be in sorted order. The method should insert a[end] into the correct spot from a[begin] to a[end] such that sorted order is maintained. For example, if array a contains {2, 4, 6, 8, 5} where begin = 0 and end = 4 then a[end] = 5 and the method should insert the value 5 between the 4 and 6, resulting in {2, 4, 5, 6, 8} . This entails copying the 6 and 8 one element to the right, and then copying the value 5 to index 2.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.