summaryrefslogtreecommitdiff
path: root/1034/CH7/EX7.2/7s2.sce
blob: 425f96d2e6c85a9508013274fb12fdfba7c971c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
clear;
clc;
disp("Example 7.2");
funcprot(0);
function[a1]=insertion(a,n)
  for k=1:n
    y=a(k);
    i=k;
    while(i>=1)
      if(y<a(i))
        a(i+1)=a(i);
        a(i)=y;
      end
      i=i-1;
    end
  end
  a1=a;
  disp(a1,"Sorted array is:");
endfunction
//Calling Routine:
a=[2 3 4 5 1]
disp(a,"Given Array");
a1=insertion(a,5)