- 爱易网页
-
C#教程
- 求解啊三个不同的函数为什么输出全一样啊该如何处理
日期:2014-05-18 浏览次数:20797 次
求解啊,三个不同的函数为什么输出全一样啊
[code=C#][/code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public struct time1
{
public float atime;
public float rtime;
public float ftime;
public float ttime;
public float wtime;
public string name;
};
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
time1[] p = new time1[5];
float[] ff = new float[6];
int i;
void sort(time1[] p)
{
for (int i = 0; i <= 4; i++)
for (int j = 0; j <= i; j++)
if (p[i].atime < p[j].atime)
{
time1 temp;
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
void deal(time1[] p,float totalTimeSum,float weightTotalTimeSum)
{
int k=0;
for(k=0;k<=4;k++)
{
if(k==0)
p[k].ftime=p[k].atime+p[k].rtime;
else
p[k].ftime=p[k-1].ftime+p[k].rtime;
}
for(k=0;k<=4;k++)
{
p[k].ttime=p[k].ftime-p[k].atime;
p[k].wtime=p[k].ttime/p[k].rtime;
totalTimeSum+=p[k].ttime;
weightTotalTimeSum+=p[k].wtime;
}
}
void FCFS(ref time1[] p)
{
float totalTimeSum = 0, weightTotalTimeSum = 0;
sort(p);
deal(p,totalTimeSum,weightTotalTimeSum);
}
void SWF(ref time1[] p)
{
float totalTimeSum = 0, weightTotalTimeSum = 0;
sort(p);
for(int m=0;m<4;m++)
{
if(m==0)
p[m].ftime=p[m].atime+p[m].rtime;
else
p[m].ftime=p[m-1].ftime+p[m].rtime;
int i=0;
for(int n=m+1;n<=4;n++)
{
if(p[n].atime<=p[m].ftime)
i++;
}
float min=p[m+1].rtime;
int follow=m+1;
for(int k=m+1;k<m+i;k++)
{
if(p[k+1].rtime<min)
{min=p[k+1].rtime;
follow=k+1;}
}
time1 temp;
temp=p[m+1];
p[m+1]=p[follow];
p[follow]=temp;
}
deal(p,totalTimeSum,weightTotalTimeSum);
}