Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

93Size
Leading solution size is 18.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
x = [5 1 4 2 8];
y_correct = 4;
assert(isequal(bubblesort(x),y_correct))
x =
     1     4     2     5     8
x =
     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))
x =
     7     9     4    17     3    17    13    19    18    20
x =
     7     4     9     3    17    13    17    18    19    20
x =
     4     7     3     9    13    17    17    18    19    20
x =
     4     3     7     9    13    17    17    18    19    20
x =
     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))
%
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))
x =
    72    27    56    16    12    21    12    19     1     9    52    44    73
x =
    27    56    16    12    21    12    19     1     9    52    44    72    73
x =
    27    16    12    21    12    19     1     9    52    44    56    72    73
x =
    16    12    21    12    19     1     9    27    44    52    56    72    73
x =
    12    16    12    19     1     9    21    27    44    52    56    72    73
x =
    12    12    16     1     9    19    21    27    44    52    56    72    73
x =
    12    12     1     9    16    19    21    27    44    52    56    72    73
x =
    12     1     9    12    16    19    21    27    44    52    56    72    73
x =
     1     9    12    12    16    19    21    27    44    52    56    72    73
x =
     4     2     5     1     5     8     6    12    13    15     7    22
x =
     2     4     1     5     5     6     8    12    13     7    15    22
x =
     2     1     4     5     5     6     8    12     7    13    15    22
x =
     1     2     4     5     5     6     8     7    12    13    15    22
x =
     1     2     4     5     5     6     7     8    12    13    15    22
x =
  Columns 1 through 16
    15    16    48    86    29    56     2    59    57     2     6    27    53    89    29    52
  Columns 17 through 30
    32     4    61    67    18    91    12    37    76    71    85    91     9    99
x =
  Columns 1 through 16
    15    16    48    29    56     2    59    57     2     6    27    53    86    29    52    32
  Columns 17 through 30
     4    61    67    18    89    12    37    76    71    85    91     9    91    99
x =
  Columns 1 through 16
    15    16    29    48     2    56    57     2     6    27    53    59    29    52    32     4
  Columns 17 through 30
    61    67    18    86    12    37    76    71    85    89     9    91    91    99
x =
  Columns 1 through 16
    15    16    29     2    48    56     2     6    27    53    57    29    52    32     4    59
  Columns 17 through 30
    61    18    67    12    37    76    71    85    86     9    89    91    91    99
x =
  Columns 1 through 16
    15    16     2    29    48     2     6    27    53    56    29    52    32     4    57    59
  Columns 17 through 30
    18    61    12    37    67    71    76    85     9    86    89    91    91    99
x =
  Columns 1 through 16
    15     2    16    29     2     6    27    48    53    29    52    32     4    56    57    18
  Columns 17 through 30
    59    12    37    61    67    71    76     9    85    86    89    91    91    99
x =
  Columns 1 through 16
     2    15    16     2     6    27    29    48    29    52    32     4    53    56    18    57
  Columns 17 through 30
    12    37    59    61    67    71     9    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2    15     2     6    16    27    29    29    48    32     4    52    53    18    56    12
  Columns 17 through 30
    37    57    59    61    67     9    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15    16    27    29    29    32     4    48    52    18    53    12    37
  Columns 17 through 30
    56    57    59    61     9    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15    16    27    29    29     4    32    48    18    52    12    37    53
  Columns 17 through 30
    56    57    59     9    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15    16    27    29     4    29    32    18    48    12    37    52    53
  Columns 17 through 30
    56    57     9    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15    16    27     4    29    29    18    32    12    37    48    52    53
  Columns 17 through 30
    56     9    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15    16     4    27    29    18    29    12    32    37    48    52    53
  Columns 17 through 30
     9    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6    15     4    16    27    18    29    12    29    32    37    48    52     9
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     6     4    15    16    18    27    12    29    29    32    37    48     9    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    15    16    18    12    27    29    29    32    37     9    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    15    16    12    18    27    29    29    32     9    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    15    12    16    18    27    29    29     9    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12    15    16    18    27    29     9    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12    15    16    18    27     9    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12    15    16    18     9    27    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12    15    16     9    18    27    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12    15     9    16    18    27    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6    12     9    15    16    18    27    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99
x =
  Columns 1 through 16
     2     2     4     6     9    12    15    16    18    27    29    29    32    37    48    52
  Columns 17 through 30
    53    56    57    59    61    67    71    76    85    86    89    91    91    99