資源簡介
操作系統(tǒng)進程調(diào)度算法 先來先服務(wù) 短作業(yè)優(yōu)先 時間片輪轉(zhuǎn) 優(yōu)先級。有大量注釋,幫助理解。目前沒有錯誤

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
struct?pcb
{
int?come_time;
int?run_time;
int?VIP;
char?name[10];
struct?pcb?*next;
};
typedef?struct?pcb?PCB;
void?*creat(int?n);
void?Firstcome_Firstserve(PCB?*head);
void?Menue(PCB?*headint?n);
void*My_Copy(PCB?*head);
void?Print(?PCB?*headint?len);
void?Shortwork_Firstserve(PCB?*head);
void?TimeTurn_Firstserve(PCB?*headint?timeturnint?n);
void?VIP_Firstserve(PCB?*head);
/************************************************************************/
/*???????????????????????????????*創(chuàng)建進程鏈表*?????????????????????????*/
/************************************************************************/?//2010_10_24
void?*creat(int?n)
{
PCB?*head*p*q;
assert?(head=(PCB*)malloc(sizeof(PCB)));??
p=head;
p->next=NULL;
while(n--)
{
p=head;
if(?(?q=(PCB*)malloc(sizeof(PCB)))?==?NULL)
{
printf(“ERROR!\n“);
exit(0);
}
puts(“進程名:“);??
getchar();??
gets(q->name);
puts(“進程開始時間“);????
scanf(“%d“&q->come_time);
puts(“進程運行時間“);?????
scanf(“%d“&q->run_time);
puts(“優(yōu)先級“);
scanf(“%d“&q->VIP);?
if(p->next==NULL)??????????//在插入節(jié)點時排序
{
q->next=NULL;
p->next=q;
}
else
{
while?(p->next!=NULL?&&?q->come_time?>p->next->come_time?)
{
p=p->next;
}
q->next=p->next;
p->next=q;
} ??????????????????????????//在插入節(jié)點時排序
}
return?head;
}
/************************************************************************/
/*???????????????????????????拷貝鏈表???????????????????????????????????*/
/************************************************************************/
void?*My_Copy(PCB?*head1)
{
PCB?*head2=NULL; //新鏈表頭結(jié)點
PCB?*p2=NULL; //
PCB?*p1=head1->next;
PCB?*node=NULL;
assert(head2=(PCB*)malloc(sizeof(PCB)));
p2=head2;
while(p1!=NULL)
{
assert(node?=?(PCB*)malloc(sizeof(PCB)));
strcpy(node->namep1->name); ?//拷貝進程
node->come_time=p1->come_time;
node->run_time=p1->run_time;
node->VIP=p1->VIP; //拷貝進程
node->next=NULL;?????
p2->next=node;
p2=p2->next; //指針后移
p1=p1->next;
}
return?head2;
}
/********************************打印輸出*****************************************/
void?Print(??PCB?*headint?len)
{
int?i=0;
head=head->next;
puts(“進程名????到達時間?????運行時間????優(yōu)先級“);
for(i=0;inext)
{
printf(“%5s?%10d?%10d?%10d\n“head->namehead->come_timehead->run_timehead->VIP);
}
}
/************************************************************************/
/*????????????????????????????*先來先服務(wù)*??????????????????????????????*/
/************************************************************************/?//2010_10_28
void?Firstcome_Firstserve(PCB?*head)
{
PCB?*Head=My_Copy(head);
int?counter=1;
PCB?*h=Head->next;
PCB?*p;
int?time;?????????//進程結(jié)束時間
int?time2;
while(h!=NULL)
{
if(h=
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????172071??2010-11-16?22:24??PCB\Debug\gaoke.exe
?????文件?????528288??2010-11-16?22:24??PCB\Debug\gaoke.ilk
?????文件??????38521??2010-11-16?22:24??PCB\Debug\gaoke.obj
?????文件????2803084??2010-11-16?12:20??PCB\Debug\gaoke.pch
?????文件?????484352??2010-11-16?22:24??PCB\Debug\gaoke.pdb
?????文件??????50176??2010-11-17?23:03??PCB\Debug\vc60.idb
?????文件??????69632??2010-11-16?22:24??PCB\Debug\vc60.pdb
?????文件??????37074??2010-11-16?22:24??PCB\gaoke.c
?????文件???????3387??2010-11-06?19:06??PCB\gaoke.dsp
?????文件????????535??2010-11-06?20:55??PCB\gaoke.dsw
?????文件??????50176??2010-11-17?23:04??PCB\gaoke.ncb
?????文件??????49664??2010-11-17?23:04??PCB\gaoke.opt
?????文件???????1142??2010-11-16?22:24??PCB\gaoke.plg
?????目錄??????????0??2010-11-18?12:11??PCB\Debug
?????目錄??????????0??2010-11-18?12:11??PCB
-----------?---------??----------?-----??----
??????????????4288102????????????????????15
評論
共有 條評論