Question: Declare and implement a new function oddevenSort ( ) by repeatedly making two passes through the array. On the first pass you look at all

Declare and implement a new function oddevenSort() by repeatedly making two
passes through the array. On the first pass you look at all the pairs of items, a[j] and
a[j+1], where j is odd (j =1,3,5,...). If their key values are out of order, you swap them.
On the second pass you do the same for all the even values (j =0,2,4,6,...). You do
these two passes repeatedly until the array is sorted.
Given:
4030105020
1st round:
4010302050(j =1,3)
2nd round:
1040203050(j =0,2)
3rd round:
1020403050(j =1,3)
4th round:
1020304050(j =0,2)
5th round:
1020304050(j =1,3)(no swap!)
6th round:
1020304050(j =0,2)(no swap!)

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 Programming Questions!