磁盘位示图管理

 

None.gif // 设计一个按优先数调度算法实现处理器调度的程序。
None.gif
#include  < iostream.h >
None.giftypedef 
struct  p
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
char name[];
InBlock.gif    
int time;
InBlock.gif    
int num;
InBlock.gif    
struct p *next;
ExpandedBlockEnd.gif}
plist;
None.gif
void  creat();
None.gif
void  sort1(plist  * L); 
None.gif
void  sort2(plist  * L);
None.gif
void  display(plist  * L); 
None.gif
void  done(plist  * L); 
None.gifplist 
* L;
None.gif
int  main()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    creat();
InBlock.gif    display(L); 
InBlock.gif    done(L); 
InBlock.gif    getchar();
InBlock.gif    getchar(); 
ExpandedBlockEnd.gif}
    
None.gif
void  creat()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    plist 
*s,*r; 
InBlock.gif    L
=new plist;
InBlock.gif    L
->next=NULL;
InBlock.gif    r
=L; 
InBlock.gif    cout
<<"              优先数进程调度模拟"<<endl<<endl; 
InBlock.gif    cout
<<"输入进程的名字,要求运行时间和优先数:"<<endl; 
InBlock.gif    
for(int i=1;i<=5;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        s
=new plist; 
InBlock.gif        
while(1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif           cout
<<""<<i<<"个进程:";
InBlock.gif           cin
>>s->name>>s->time>>s->num;
InBlock.gif           
if(s->time>0
InBlock.gif             
break;
InBlock.gif           
else cout<<"输入错误,请重新输入."<<endl;  
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        r
->next=s;
InBlock.gif        r
=s;         
ExpandedSubBlockEnd.gif    }

InBlock.gif    r
->next=NULL; 
InBlock.gif    sort1(L);  
ExpandedBlockEnd.gif}
     
None.gif
void  done(plist  * L)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
while(1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif    plist 
*p=L->next;
InBlock.gif    
if(p==NULL)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        cout
<<"所有进程执行完毕."<<endl;
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        cout
<<p->name<<"进程运行一个了单位时间."<<endl; 
InBlock.gif        p
->num-=1;
InBlock.gif        p
->time-=1
InBlock.gif        
if(p->time==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            L
->next=p->next; 
InBlock.gif            delete p;
InBlock.gif            display(L);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else  
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            sort2(L);
InBlock.gif            display(L);
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }
   
ExpandedSubBlockEnd.gif    }
 
ExpandedBlockEnd.gif}
   
None.gif
void  display(plist  * L)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    plist 
*p=L->next;
InBlock.gif    
while(p!=NULL)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        cout
<<p->name<<"    "<<p->time<<"    "<<p->num<<endl;
InBlock.gif        p
=p->next;
ExpandedSubBlockEnd.gif    }

InBlock.gif    cout
<<endl;
ExpandedBlockEnd.gif}
 
None.gif
void  sort1(plist  * L)     // 链表排序
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {  
InBlock.gif   plist 
*p=L->next, *q, *r;
InBlock.gif   
if(p!=NULL)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif      r
=p->next;
InBlock.gif      p
->next=NULL;
InBlock.gif      p
=r;
InBlock.gif      
while(p!=NULL)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif        r
=p->next;
InBlock.gif        q
=L;
InBlock.gif        
while(q->next!=NULL&&q->next->num>p->num)
InBlock.gif           q
=q->next;
InBlock.gif        p
->next=q->next;
InBlock.gif        q
->next=p;
InBlock.gif        p
=r;
ExpandedSubBlockEnd.gif      }
 
ExpandedSubBlockEnd.gif   }
      
ExpandedBlockEnd.gif}
        
None.gif
void  sort2(plist  * L)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    plist 
*p=L->next,*q,*r;
InBlock.gif    L
->next=p->next;
InBlock.gif    q
=L->next;
InBlock.gif    r
=L;
InBlock.gif    
while(q!=NULL&&q->num>=p->num)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        r
=q;
InBlock.gif        q
=r->next;
ExpandedSubBlockEnd.gif    }
    
InBlock.gif    r
->next=p;
InBlock.gif    p
->next=q;     
ExpandedBlockEnd.gif}
            
None.gif

转载于:https://www.cnblogs.com/newzpflying/archive/2006/02/24/337258.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值