Cody

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

Solution 2884058

Submitted on 27 Aug 2020 by Pauli Huusari
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   Pass
x = [5 1 4 2 8]; y_correct = 4; assert(isequal(bubblesort(x),y_correct))

tyo_vektori = 1 2 4 5 8

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

tyo_vektori = 3 4 7 9 13 17 17 18 19 20

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

tyo_vektori = 1 9 12 12 16 19 21 27 44 52 56 72 73

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

tyo_vektori = 1 2 4 5 5 6 7 8 12 13 15 22

5   Pass
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))

tyo_vektori = Columns 1 through 29 2 2 4 6 9 12 15 16 18 27 29 29 32 37 48 52 53 56 57 59 61 67 71 76 85 86 89 91 91 Column 30 99

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!