📄 1.zip.txt
字号:
#include<stdio.h>
#include<math.h>
#include<malloc.h>
#define null 0
#define len sizeof(struct process)
int shumu,jin,min,zhong,x,y,c,d;
int m=0,n=0,ji=1,zhu=10,wu=0;
int k=0;
struct process
{
int name;
int zhuhao;
int wulihao;
struct process *next;
};
struct process *arry[10],*b[10];
struct process chu={0,0,0};
struct process *p1,*p2;
struct process *head,*p;
struct process *chushi(void)
{
printf("请输入 名字 柱号 物理号:(名字为0时止)\n");
shumu=0;
p1=p2=(struct process *)malloc(len);
scanf("%d %d %d",&p1->name,&p1->zhuhao,&p1->wulihao);
head=null;
while(p1->name!=0)
{
if(shumu==0){head=p1;}
else{p2->next=p1;
p2=p1;
p1=(struct process *)malloc(len);
scanf("%d %d %d",&p1->name,&p1->zhuhao,&p1->wulihao);
if(p1->name==0){break;}
}
shumu=shumu+1;
}
p2->next=null;
return (head);
}
struct process *qingqiu(void)
{
printf("是否请求?是-1");
scanf("%d",&y);
if(y==1){
printf("请按格式输入名字 柱号 物理号:\n");
struct process *p0;
p0=(struct process *)malloc(len);
p0->next=head;
head=p0;
shumu=shumu+1;
scanf("%d %d %d",&p0->name,&p0->zhuhao,&p0->wulihao);
}
return(head);
}
struct process *shanchu(void)
{
p1=head;
while(chu.name!=p1->name&&p1->next!=null){
p2=p1;
p1=p1->next;
}
if(chu.name==p1->name){
if(p1==head){
head=p1->next;}
else{p2->next=p1->next;}
shumu=shumu-1;}
else{printf("找不到");
}
return (head);
}
struct process *dayin(void)
{
p=head;
if(head!=null)
{
while(p!=null)
{
printf("\t%d %d %d\n",p->name,p->zhuhao,p->wulihao);
p=p->next;
}
}
return(head);
}
void zuijin()
{ min=4;
for(c=0;c<d;c++){//找出最进的号
jin=wu-b[c]->wulihao;
if(jin==0){
//printf("找到的为:");
//printf("%d\t%d\t%d\n",b[c]->name,b[c]->zhuhao,b[c]->wulihao);
min=0;break;
}
if(jin!=0){
if(jin>4){
jin=(8-jin);}
if(jin<0){
if(jin<-4){
jin=8+jin;}
else{
jin=0-jin;}
}
if(min>jin){min=jin;}
}
}
for(c=0;c<d;c++){//比较找出与上面号相等的
jin=wu-b[c]->wulihao;
if(jin>4){
jin=(8-jin);}
if(jin<0){
if(jin<-4){
jin=8+jin;}
else{
jin=0-jin;}
}
if(jin==min){ //printf("找到的为:");
//printf("%d\t%d\t%d\n",b[c]->name,b[c]->zhuhao,b[c]->wulihao);
chu=*b[c];}
}
}
void qudong(){
m=0;n=0;c=0;d=0;
if(k==0){ printf("当前方向向里(即序号增大方向)\n"); //向里移
p=head;
if(head!=null){
while(p!=null){
if(p->zhuhao>=zhu){
arry[m]=p;
m++;n++;
}
p=p->next;
}
}
if(n>0){ //有比当前柱号大的
if(n!=1){zhong=arry[0]->zhuhao;
for(m=0;m<n;m++){//找到柱号最小的
if(zhong>=arry[m]->zhuhao){
zhong=arry[m]->zhuhao;}
}
for(m=0;m<n;m++){//把所有柱号符合的防入数组
if(arry[m]->zhuhao==zhong){
b[c]=arry[m];
c++;d++;
}
}
zuijin();
}
else {
chu=*arry[m-1];}
printf("找到的是:\n");
printf("\t%d %d %d",chu.name,chu.zhuhao,chu.wulihao);
printf(" up\n");//可能不写
}
if(n==0){k=1;printf("改变方向向外\n");}//跳到想外的
}
if(k==1){
printf("当前方向向外(即序号增小方向)\n"); //向外移
p=head;
if(head!=null){
while(p!=null){
if(zhu>=p->zhuhao){
arry[m]=p;
m++;n++;
}
p=p->next;
}
}
if(n>0){ //有比当前柱号小的
if(n!=1){zhong=arry[0]->zhuhao;
for(m=0;m<n;m++){//找到柱号最大的
if(zhong<=arry[m]->zhuhao){
zhong=arry[m]->zhuhao;}
}
for(m=0;m<n;m++){//把所有柱号符合的放入数组
if(arry[m]->zhuhao==zhong){
b[c]=arry[m];
c++;d++;
}
}
zuijin();
}
else {
chu=*arry[m-1];}
printf("找到的是:\n");
printf("\t%d %d %d",chu.name,chu.zhuhao,chu.wulihao);
printf(" down\n");
}
if(n==0){k=0;printf("改变方向向里\n");}//跳到向里的
}
zhu=chu.zhuhao; //记录当前的位置
wu=chu.wulihao;
}
void main()
{
chushi();
while(ji==1){
if(shumu==0){break;}
else{
printf("请输入一个随机数(大于0调度,其他为请求):\t");
scanf("%d",&x);
if(x>0){
qudong();
shanchu();
printf("当前的请求表如下:\n");
dayin();
}
else{qingqiu();
printf("当前的请求表如下:\n");
dayin();}
printf("是否继续?是-1");
scanf("%d",&ji);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -