testmergesorted.m

来自「If we have two individually sorted vecto」· M 代码 · 共 35 行

M
35
字号
clc,clear all

orga=sort(rand(1,2000000)); % generate 2 million   random numbers and sort them (first vector)
orgb=sort(rand(1,2500000)); % generate 2.5 million random numbers and sort them (second vector)


% % Merging two sorted vectors using 'mergesorted' function
a=orga;
b=orgb;
time = cputime;
c2=mergesorted(a,b);
time_mergesorted = cputime-time

% % Merging two sorted vectors using MATLAB built in functions
a=orga;
b=orgb;
time = cputime;
c1=sort([a,b]);
time_builtin = cputime-time

if(~isequal(c1,c2) || ~issorted(c1) || ~issorted(c2)  )
    error('problem: report to author')
end

TimeRatio=time_builtin/time_mergesorted

% % Copyright
% % This program or any other program(s) supplied with it does not
% % provide any warranty direct or implied. This program is free to
% % use/share for non-commerical purpose only as long as author is referenced.
% % For commerical purpose usage contact with author:
% % contact: M A Khan
% % Email: khan_goodluck@yahoo.com
% % http://www.m-a-khan.blinkz.com/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?