Cody

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

Solution 226048

Submitted on 1 Apr 2013 by andrea84
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))

``` n = 1 n = 2 n = 3 n = 4 ```

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

``` n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 ```

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)) % x = [4 15 2 5 1 5 8 6 12 13 22 7]; y_correct = 18; assert(isequal(bubblesort(x),y_correct)) % 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))

``` n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15 n = 16 n = 17 n = 18 n = 19 n = 20 n = 21 n = 22 n = 23 n = 24 n = 25 n = 26 n = 27 n = 28 n = 29 n = 30 n = 31 n = 32 n = 33 n = 34 n = 35 n = 36 n = 37 n = 38 n = 39 n = 40 n = 41 n = 42 n = 43 n = 44 n = 45 n = 46 n = 47 n = 48 n = 49 n = 50 n = 51 n = 52 n = 53 n = 54 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15 n = 16 n = 17 n = 18 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 n = 10 n = 11 n = 12 n = 13 n = 14 n = 15 n = 16 n = 17 n = 18 n = 19 n = 20 n = 21 n = 22 n = 23 n = 24 n = 25 n = 26 n = 27 n = 28 n = 29 n = 30 n = 31 n = 32 n = 33 n = 34 n = 35 n = 36 n = 37 n = 38 n = 39 n = 40 n = 41 n = 42 n = 43 n = 44 n = 45 n = 46 n = 47 n = 48 n = 49 n = 50 n = 51 n = 52 n = 53 n = 54 n = 55 n = 56 n = 57 n = 58 n = 59 n = 60 n = 61 n = 62 n = 63 n = 64 n = 65 n = 66 n = 67 n = 68 n = 69 n = 70 n = 71 n = 72 n = 73 n = 74 n = 75 n = 76 n = 77 n = 78 n = 79 n = 80 n = 81 n = 82 n = 83 n = 84 n = 85 n = 86 n = 87 n = 88 n = 89 n = 90 n = 91 n = 92 n = 93 n = 94 n = 95 n = 96 n = 97 n = 98 n = 99 n = 100 n = 101 n = 102 n = 103 n = 104 n = 105 n = 106 n = 107 n = 108 n = 109 n = 110 n = 111 n = 112 n = 113 n = 114 n = 115 n = 116 n = 117 n = 118 n = 119 n = 120 n = 121 n = 122 n = 123 n = 124 n = 125 n = 126 n = 127 n = 128 n = 129 n = 130 n = 131 n = 132 n = 133 n = 134 n = 135 n = 136 n = 137 n = 138 n = 139 n = 140 n = 141 n = 142 n = 143 n = 144 n = 145 n = 146 n = 147 n = 148 n = 149 n = 150 n = 151 n = 152 n = 153 n = 154 n = 155 n = 156 n = 157 n = 158 n = 159 n = 160 n = 161 n = 162 n = 163 n = 164 n = 165 n = 166 n = 167 n = 168 n = 169 n = 170 n = 171 n = 172 n = 173 n = 174 n = 175 n = 176 n = 177 n = 178 n = 179 n = 180 ```