| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1152 人关注过本帖
标题:求个进程调度高响应比优先权算法,不会计算优先权
只看楼主 加入收藏
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:5 
求个进程调度高响应比优先权算法,不会计算优先权
#include<iostream>
using namespace std;
typedef struct PCB
{
int id;   //进程名字p1、p2、p3、p4、p5
struct PCB *next;//指针指向下一个位置
float runtime; //到达时间
float priority;//优先级
float stime;//服务时间
}*pcb;
void create(PCB *h)  
{
    float a,c;  //a运行时间、b进程优先级
PCB *q,*p;
h->next=NULL;
p=h;
for(int i=0;i<5;i++)
{
cout<<"-------P"<<i+1<<" :"<<endl;
cin>>a>>c;
q=new PCB;
q->id=i+1;        
q->runtime=a;
q->stime=c;
p->next=q;
p=q;
}
p->next=NULL;
}
float priority(PCB *h)
{
    PCB *s;
    s=h->next;
    while(s!=NULL)
    {   
        //s->next->wtime=(s->stime-s->next->runtime);
        s->next->priority=(1+(s->stime-s->next->runtime))/s->next->stime;

       s=s->next;
    return s->next->priority;


    }
 
}
void display(PCB *h)
{
    PCB *s=h->next;
    while(s!=NULL)
    {    cout<<"runtime"<<"  "<<"stime"<<"  "<<"priority"<<endl;
        cout<<s->runtime<<"       "<<s->stime<<"      "<<s->priority<<endl;

        s=s->next;
    }
}
int  main()
{    PCB *h=new PCB;
    create(h);
    //priority(h);
    display(h);
 
 cout<< priority(h)<<"  ";
return 0;
}
搜索更多相关主题的帖子: create include next 优先权 
2012-12-25 15:28
w527705090
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:441
专家分:1882
注 册:2011-6-28
收藏
得分:7 
看这贴子在这里挂了好几天了,估计是这个进程高度响应优先级别没什么人知道,当然,包括我在内。
现在只好帮顶了。。。

有心者,千方百计;无心者,千难万难。
2012-12-26 15:11
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 
谢谢啦!

同学习......同进步....你帮我......我帮你.....上善若水.....
2012-12-27 17:19
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 


#include<iostream>
using namespace std;
typedef struct PCB
{
char id;   //进程名字p1、p2、p3、p4、p5
struct PCB *next;//指针指向下一个位置
float runtime; //到达时间
float priority;//优先级
float wtime;
float stime;//服务时间
int flag;
}*pcb;
void create(PCB *h)  
{
    float a,c; //a运行时间、b进程优先级
    char d;
PCB *q,*p;
h->next=NULL;
p=h;
for(int i=0;i<5;i++)
{
cout<<"-------P"<<i+1<<" :"<<endl;
cin>>d>>a>>c;
q=new PCB;
q->id=d;        
q->runtime=a;
q->stime=c;
q->flag=1;
p->next=q;
p=q;
}
p->next=NULL;
}
void priority(PCB *h)
{
    PCB *s,*s1,*s2;
    s=h->next;
    cout<<s->id;
    float cur=0;
    float cur1=0;
    cur+=s->stime;
    s->flag=0;
    s=s->next;
    s1=s;
    s2=s;
    int i=4;
    while(i)
    {    s=s2;
        s1=s2;
    while(s!=NULL)
    {    if(s->flag==1)
        {
        s->priority=1+(cur-s->runtime)/s->stime;
        if((s->priority>cur1))
        cur1=s->priority;   
        }
        s=s->next;
    }
    while(s1!=NULL)
    {    if((s1->priority==cur1)&&(s1->flag==1))
            {
                    cout<<s1->id;
                    s1->flag=0;
                    cur+=s1->stime;
                    cur1=0;
            }
            s1=s1->next;
    }
    i--;
    }
 
}
void display(PCB *h)
{
    PCB *s=h->next;
    while(s!=NULL)
    {    cout<<"runtime"<<"  "<<"stime"<<"  "<<"priority"<<endl;
        cout<<s->runtime<<"       "<<s->stime<<"      "<<s->priority<<endl;

        s=s->next;
    }
}
int  main()
{    PCB *h=new PCB;
    create(h);
    priority(h);
    //display(h);
 
 //cout<< priority(h)<<"  ";
return 0;
}

同学习......同进步....你帮我......我帮你.....上善若水.....
2012-12-27 17:20
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 


#include
using namespace std;
typedef struct PCB
{
char id;   //进程名字p1、p2、p3、p4、p5
struct PCB *next;//指针指向下一个位置
float runtime; //到达时间
float priority;//优先级
float wtime;
float stime;//服务时间
int flag;
}*pcb;
void create(PCB *h)  
{
    float a,c; //a运行时间、b进程优先级
    char d;
PCB *q,*p;
h->next=NULL;
p=h;
for(int i=0;i<5;i++)
{
cout<<"-------P"<id;
    float cur=0;
    float cur1=0;
    cur+=s->stime;
    s->flag=0;
    s=s->next;
    s1=s;
    s2=s;
    int i=4;
    while(i)
    {    s=s2;
        s1=s2;
    while(s!=NULL)
    {    if(s->flag==1)
        {
        s->priority=1+(cur-s->runtime)/s->stime;
        if((s->priority>cur1))
        cur1=s->priority;   
        }
        s=s->next;
    }
    while(s1!=NULL)
    {    if((s1->priority==cur1)&&(s1->flag==1))
            {
                    cout<id;
                    s1->flag=0;
                    cur+=s1->stime;
                    cur1=0;
            }
            s1=s1->next;
    }
    i--;
    }
 
}
void display(PCB *h)
{
    PCB *s=h->next;
    while(s!=NULL)
    {    cout<<"runtime"<<"  "<<"stime"<<"  "<<"priority"<runtime<<"       "<stime<<"      "<priority<<ENDL;

        s=s->next;
    }
}
int  main()
{    PCB *h=new PCB;
    create(h);
    priority(h);
    //display(h);
 
 //cout<< priority(h)<<"  ";
return 0;
}
</i+1<<" :"<<endl;

同学习......同进步....你帮我......我帮你.....上善若水.....
2012-12-27 17:20
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 
求个大神改改,谢谢!

同学习......同进步....你帮我......我帮你.....上善若水.....
2012-12-27 17:21
快速回复:求个进程调度高响应比优先权算法,不会计算优先权
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015150 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved