Cody

Problem 1401. Implement a bubble sort technique and output the number of swaps required

Solution 1854676

Submitted on 20 Jun 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
x = [5 1 4 2 8]; y_correct = 4; assert(isequal(bubblesort(x),y_correct))

x = 6 10 12 20 20 x = 6 10 12 20 20

Assertion failed.

2   Fail
x = [7 9 17 4 19 3 17 13 20 18]; y_correct = 14; assert(isequal(bubblesort(x),y_correct))

x = 7 9 21 40 43 60 73 93 111 111 x = 7 9 21 40 43 60 73 93 111 111

Assertion failed.

3   Fail
x = [73 72 27 56 16 12 21 12 19 1 9 52 44]; y_correct = 54; assert(isequal(bubblesort(x),y_correct))

x = 145 172 228 244 256 277 289 308 309 318 370 414 414 x = 145 172 228 244 256 277 289 308 309 318 370 414 414

Assertion failed.

4   Fail
x = [4 15 2 5 1 5 8 6 12 13 22 7]; y_correct = 18; assert(isequal(bubblesort(x),y_correct))

x = 4 17 22 23 28 36 42 54 67 89 96 96 x = 4 17 22 23 28 36 42 54 67 89 96 96

Assertion failed.

5   Fail
x = [48 15 16 86 89 29 56 2 59 57 2 6 27 53 91 29 52 32 4 61 67 18 99 12 37 76 71 85 91 9]; y_correct = 180; assert(isequal(bubblesort(x),y_correct))

x = Columns 1 through 15 63 79 79 86 118 174 176 235 292 294 300 327 380 471 500 Columns 16 through 30 552 584 588 649 716 734 833 845 882 958 1029 1114 1205 1214 1214 x = Columns 1 through 15 63 79 79 86 118 174 176 235 292 294 300 327 380 471 500 Columns 16 through 30 552 584 588 649 716 734 833 845 882 958 1029 1114 1205 1214 1214

Assertion failed.