Tita (chiquitavi) wrote in matlab_help,
Tita
chiquitavi
matlab_help

New to Matlab

Hello all. I'm completing an assignment on matlab and we were asked to change C++ coding to matlab coding but I'm not sure how to go about this (basically creating an M-file for the Insertion Sort Algorithm that accepts an array a) Thank you for any help in advance Here is the C++ code: 
insert(array a,  int length, value) {
         int i = length -1;
         while (i >= 0 && a[i] > value) {
               a[i +1] = a[i];
               i = i - 1;
         }
         a[i + 1]   :=value;
}

insertionSort(array a, int length) {
        int i = 0;
       while (i < length)   {
                  insert(a, i, a[ i ]);
       }
}
 
  • Post a new comment

    Error

    default userpic
  • 6 comments