0

这是我的原始代码:

function a = graph_times()
merge_times = [];
for i = 100:100:1000
    curr = sort_timer(i);
    merge_times = [merge_times, curr(1)];
end
plot(100:100:1000, merge_times);

a = 1;
end

insertion_sort我想修改此代码,以便merge_sort在同一图表上绘制趋势线。下面是函数merge_sortinsertion_sort

function c = insertion_sort(list1)
inserted = [];
for i = 1:size(list1,2)
inserted = insert_in_order(inserted,list1(1,i))
c = inserted
end
steps2=0;

function b = merge_sort(nums)
    if size(nums,2) == 1
        b = nums;
        return;
    end
4

1 回答 1

0

plot您可以为 MATLAB 的函数提供多组坐标。您可以像这样绘制两种排序算法的时间:

plot(100:100:1000, merge_times, 100:100:1000, insertion_times);
于 2013-04-20T00:46:08.610 回答