clear all;

clc;

close all;

num = [261.5700,257.0460,569.100,509.1350,5116.3,5075.2,10651,10169,20812,20913];

count1 = [16.8868,13.4084,3.1702,2.8441,1.14615,1.2604,1.7736,3.6653,2.1190,2.9398];

count2 = [1,1,1,1.0021,1.0213,1.0237,1.0444,1.0659,1.0893,1.1403];

count3 = [14.9574,29.3545,12.0400,4.4365,4,5.1343,6.8261,19.2194,5.8958,10.5320];

count4 = [1,1,1,1,1,1.2928,2.2105,2.2927,1.5854,2.7640];

t1 = [0.029538,0.14186,0.046396,0.11342,0.13859,0.18101,0.39743,0.84583,0.46345,0.7976];

t2 = [0.022026,0.23697,0.047947,0.05673,0.44638,0.905506,0.59066,0.80332,0.67733,0.77077];

t3 = [0.024129,0.11344,0.050093,0.097085,0.19823,0.20138,0.42419,0.84736,0.6377,0.82311];

t4 = [0.031323,0.21113,0.054082,0.46642,0.48595,0.76325,0.75622,0.82805,0.65786,0.79749];

j = 1;

figure;

for i = 2:2:length(num)

   x(j) = num(i);

   y1(j) = count1(i);

   y2(j) = count2(i);

   y3(j) = count3(i);

   y4(j) = count4(i);

   j = j + 1;

end

plot(x,y1,'r');

hold on;

plot(x,y2,'b');

hold on;

plot(x,y3,'g');

hold on;

plot(x,y4,'m');

title('申请1000次的平均内存申请大小与平均查找次数之间的关系');

xlabel('平均内存申请大小');

ylabel('平均查找次数');

legend('首次适应算法','循环首次适应算法','最佳适应算法','最坏适应算法');

clear x y1 y2 y3 y4


figure;

for i = 2:2:length(num)

   x(j) = num(i);

   y1(j) = t1(i)*100;

   y2(j) = t2(i)*100;

   y3(j) = t3(i)*100;

   y4(j) = t4(i)*100;

   j = j + 1;

end

plot(x,y1,'r');

hold on;

plot(x,y2,'b');

hold on;

plot(x,y3,'g');

hold on;

plot(x,y4,'m');

title('申请1000次的平均内存申请大小与平均利用率之间的关系');

xlabel('平均内存申请大小');

ylabel('平均内存利用率');

legend('首次适应算法','循环首次适应算法','最佳适应算法','最坏适应算法');