这是我的原始代码:
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_sort
和insertion_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
答案 0 :(得分:0)
您可以为MATLAB的plot
函数提供几组坐标。您可以绘制两种排序算法的时间,如下所示:
plot(100:100:1000, merge_times, 100:100:1000, insertion_times);