Question: Implement a version of bubble sort that alternates left - to - right and right - to - left passes through the data. For example,

Implement a version of bubble sort that alternates left-to-right and right-to- left passes through the data. For example, if sorting the array [6,5,2,8,3,1], the first left-to-right pass will swap elements that are out of order and get the result: [5,2,6,3,1,8]. The right-to-left pass begins at element 1(on position 5) and goes all the way to the beginning of the array. At the end of this pass we have [1,5,2,6,3,8]. The next phase works only on the segment [5,2,6,3] as elements 1 and 8 have already been placed at their final location.
Show how your algorithm sorts the following array: Print the status of the array at the end of each left-to-right and right-to-left pass.You must include the followings: 1) a listing of your algorithm (pseudo code),2) print the status of the input array at the end of each left-to-right and right-to-left pass, 3) Source code (C++)

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!