diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /1034/CH7/EX7.5/7s5.sce | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '1034/CH7/EX7.5/7s5.sce')
-rwxr-xr-x | 1034/CH7/EX7.5/7s5.sce | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/1034/CH7/EX7.5/7s5.sce b/1034/CH7/EX7.5/7s5.sce new file mode 100755 index 000000000..d8ee9e8f1 --- /dev/null +++ b/1034/CH7/EX7.5/7s5.sce @@ -0,0 +1,48 @@ +clear;
+clc;
+disp("Example 7.5");
+funcprot(0);
+function[a1]=mergesort(a,p,r)
+ if(p<r)
+ q=int((p+r)/2);
+ a=mergesort(a,p,q);
+ a=mergesort(a,q+1,r);
+ a=merge(a,p,q,r);
+ else
+ a1=a;
+ return;
+ end
+ a1=a;
+endfunction
+function[a1]=merge(a,p,q,r)
+ n1=q-p+1;
+ n2=r-q;
+ left=zeros(n1+1);
+ right=zeros(n2+1);
+ for i=1:n1
+ left(i)=a(p+i-1);
+ end
+ for i1=1:n2
+ right(i1)=a(q+i1);
+ end
+ left(n1+1)=999999999;
+ right(n2+1)=999999999;
+ i=1;
+ j=1;
+ k=p;
+ for k=p:r
+ if(left(i)<=right(j))
+ a(k)=left(i);
+ i=i+1;
+ else
+ a(k)=right(j);
+ j=j+1;
+ end
+ end
+ a1=a;
+endfunction
+//Calling Routine:
+a=[26 5 77 1 61 11 59 15 48 19]
+disp(a,"Given Array");
+a1=mergesort(a,1,10)
+disp(a1,"Sorted array is:");
\ No newline at end of file |