Question: SORTING: An array is said to be ordere order. In an ascending ordered array, the value of each element is less than or equal to

 SORTING: An array is said to be ordere order. In an

SORTING: An array is said to be ordere order. In an ascending ordered array, the value of each element is less than or equal to the value of the next element. That is, [each element] [next element) ts values are either ascending or descending sort is an algorithm for ordering an array. Of the many different techniques for sorting an array we discuss the bubble sort It requires the swapping of values sorted in a pair of variables. If varl, var2, and temp are all variables of the same type, then the statements temp-varl varl-var2 var2-temp Assign varl's value to var2 and var2's value to varl Bubble Sort: The bubble sort is an algorithm that compares adjacent items and swaps those that are out of order. If this process repeated enough times, the list will be ordered Let's carry out this process on the list. The stens for eacle pass through the list are as follows: 1.Compare the first and second items. If they are out of order, swap them. 2. Compare the second and third item. If they are out of order, swap them. 3.Repeat this pattern for all remaining pairs. The first time through the list, this process is repeated to the end of the list. This is called first pass. After the first pass the last item will be in its proper position. Therefore, the second pass does not have to consider it and so requires one less comparison. At the end of the second pass, the last two items will be in the proper positi on. Each successive pas quires one less comparison. After four passes, the last four items will be in their re proper positions, and hence, the first will be also 21 13 17 5 3 As a specific example of this process, consider the list of numbers: e first pass through the data and results in the largest numher process completes th to the bottom of the list. As the largest value sinks to its resting place at the om of the list, the smaller elements slowly rise, or "bubble" to the top of the list This bubbing effect of the smaller elements is what cave rise to the name "bubble IS sort for this sorting alzorithm tho void PrintList () void BubbleSort () void SortListO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!