#include"iostream"
using namespace std;
typedef struct
{
char jc[10];
int front,rear;
}sequeue;
typedef struct node4
{
char name[10];
int state;
sequeue * head;
}chct;
typedef struct node3
{
char name[10];
int state;
sequeue * head;
chct * next;
}coct;
typedef struct node1
{
int state;
sequeue * head;
coct * next;
}dct;
typedef struct node2
{
char name;
char type;
dct * next;
struct node2 * next1;
}sdt;
sdt * b;
chct * n,*n1;
void init()
{
sdt * p,* p1,* p2,* p3;
dct * q,* q1,* q2,* q3;
coct * m,* m1,*m2;
b=(sdt *)malloc(sizeof(sdt));
p=(sdt *)malloc(sizeof(sdt));
p1=(sdt *)malloc(sizeof(sdt));
p2=(sdt *)malloc(sizeof(sdt));
p3=(sdt *)malloc(sizeof(sdt));
q=(dct *)malloc(sizeof(dct));
q1=(dct *)malloc(sizeof(dct));
q2=(dct *)malloc(sizeof(dct));
q3=(dct *)malloc(sizeof(dct));
m=(coct *)malloc(sizeof(coct));
m1=(coct *)malloc(sizeof(coct));
m2=(coct *)malloc(sizeof(coct));
n=(chct *)malloc(sizeof(chct));
n1=(chct *)malloc(sizeof(chct));
p->name='K';
p->type='i';
p1->name='M';
p1->type='i';
p2->name='T';
p2->type='o';
p3->name='P';
p3->type='o';
q->state=0;
q1->state=0;
q2->state=0;
q3->state=0;
strcpy(m->name,"coct1");
strcpy(m1->name,"coct2");
strcpy(m2->name,"coct3");
m->state=0;
m1->state=0;
m2->state=0;
strcpy(n->name,"chct1");
strcpy(n1->name,"chct2");
n->state=0;
n1->state=0;
p->next=q;
p1->next=q1;
p2->next=q2;
p3->next=q3;
p3->next1=NULL;
p->next1=p1;
p1->next1=p2;
p2->next1=p3;
q->next=m;
q1->next=m;
q2->next=m1;
q3->next=m2;
m->next=n;
m1->next=n1;
m2->next=n1;
b->next1=p;
q->head=(sequeue *)malloc(sizeof(sequeue));
q->head->front=-1;
q->head->rear=-1;
q1->head=(sequeue *)malloc(sizeof(sequeue));
q1->head->front=-1;
q1->head->rear=-1;
q2->head=(sequeue *)malloc(sizeof(sequeue));
q2->head->front=-1;
q2->head->rear=-1;
q3->head=(sequeue *)malloc(sizeof(sequeue));
q3->head->front=-1;
q3->head->rear=-1;
m->head=(sequeue *)malloc(sizeof(sequeue));
m->head->front=-1;
m->head->rear=-1;
m1->head=(sequeue *)malloc(sizeof(sequeue));
m1->head->front=-1;
m1->head->rear=-1;
m2->head=(sequeue *)malloc(sizeof(sequeue));
m2->head->front=-1;
m2->head->rear=-1;
n->head=(sequeue *)malloc(sizeof(sequeue));
n->head->front=-1;
n->head->rear=-1;
n1->head=(sequeue *)malloc(sizeof(sequeue));
n1->head->front=-1;
n1->head->rear=-1;
}
int empty(sequeue * sq)
{
if(sq->rear==sq->front)
return 1;
else
return 0;
}
void show()
{
sdt * temp=b->next1;
while(temp!=NULL)
{
cout<<" "<<"设备名称 类型"<<" "<<"dct设备状态"<<" "<<"coct名称"<<" "<<"chct名称"<<endl;
cout<<" "<<temp->name<<" "<<temp->type<<" "<<temp->next->state<<" "<<temp->next->next->name<<" "<<temp->next->next->next->name<<endl;
cout<<"设备状态 "<<temp->next->next->state<<" "<<temp->next->next->next->state<<endl;
temp=temp->next1;
}
}
void a()
{
int a;
char temp;
char leixing;
sdt * temp1=b->next1;
sdt * temp0=b->next1;
sdt * s;
dct * s1;
cout<<"请输入添加设备名称 类型"<<endl;
cin>>temp>>leixing;
while(temp1->next1!=NULL)
{
temp1=temp1->next1;
}
s=(sdt *)malloc(sizeof(sdt));
s->name=temp;
s->type=leixing;
s->type=0;
s1=(dct *)malloc(sizeof(dct));
s1->head=(sequeue *)malloc(sizeof(sequeue));
s1->head->front=s1->head->rear=-1;
s1->state=0;
cout<<"请输入是否添加新的coct 1-》是 0-》不是"<<endl;
cin>>a;
if(a==1)
{
int c;
char tempname[10];
cout<<"put coct name"<<endl;
cin>>tempname;
coct * temp2;
temp2=(coct *)malloc(sizeof(coct));;
temp2->head=(sequeue *)malloc(sizeof(sequeue));
temp2->head->front=temp2->head->rear=-1;
strcpy(temp2->name,tempname);
temp2->state=0;
cout<<"请选择1-》chct1 2-》chct2"<<endl;
cin>>c;
if(c==1)
{
temp1->next1=s;
s->next1=NULL;
s->next=s1;
s1->next=temp2;
temp2->next=n;
}
if(c==2)
{
temp1->next1=s;
s->next1=NULL;
s->next=s1;
s1->next=temp2;
temp2->next=n1;
}
cout<<"添加成功"<<endl;
}
else
{
int c;
//cout<<"请输入coct名称"<<endl;
char tempname[10];
cout<<"put coct name"<<endl;
cin>>tempname;
while(temp0!=NULL)
{
if(strcmp(temp0->next->next->name,tempname)==0)
{
break;
}
temp0=temp0->next1;
}
cout<<"请选择1-》chct1 2-》chct2"<<endl;
cin>>c;
if(c==1)
{
temp1->next1=s;
s->next1=NULL;
s->next=s1;
s1->next=temp0->next->next;
temp0->next->next->next=n;
}
if(c==2)
{
temp1->next1=s;
s->next1=NULL;
s->next=s1;
s1->next=temp0->next->next;
temp0->next->next->next=n;
}
cout<<"添加成功"<<endl;
}
}
void d()
{
char a;
int cut=0;
cout<<"请输入要删除的设备名称"<<endl;
cin>>a;
sdt * temp=b->next1;
sdt * temp1=b->next1;
sdt * temp0=b;
while(temp1!=NULL)
{
if(temp1->name==a)
break;
temp1=temp1->next1;
temp0=temp0->next1;
}
while(temp!=NULL)
{
if(temp->next->next->name==temp1->next->next->name)
cut=cut+1;
temp=temp->next1;
}
if(cut==1)
{
//free(temp1->next->next);
temp0->next1=temp1->next1;
}
else
{
temp0->next1=temp1->next1;
}
}
void s()
{
char a,c;
cout<<"请输入进程名"<<endl;
cin>>a;
cout<<"请输入设备名"<<endl;
cin>>c;
sdt * temp1=b->next1;
// sdt * temp0=b->next1;
while(temp1!=NULL)
{
if(temp1->name==c)
break;
temp1=temp1->next1;
}
if(temp1->next->state==0)
{
if(temp1->next->next->state==0)
{
if(temp1->next->next->next->state==0)
{
temp1->next->state=1;
temp1->next->next->state=1;
temp1->next->next->next->state=1;
}
else
{
temp1->next->next->next->head->rear=(n->head->rear+1)%10;
temp1->next->next->next->head->jc[n->head->rear]='a';
}
}
else
{
temp1->next->next->head->rear=(temp1->next->next->head->rear+1)%10;
temp1->next->next->head->jc[temp1->next->next->head->rear]='a';
}
}
else
{
temp1->next->head->rear=(temp1->next->head->rear+1)%10;
temp1->next->head->jc[temp1->next->head->rear]='a';
}
}
void r()
{
char a;
cout<<"请输入释放备名称"<<endl;
cin>>a;
sdt * temp1=b->next1;
while(temp1!=NULL)
{
if(temp1->name==a)
break;
temp1=temp1->next1;
}
if(empty(temp1->next->next->next->head))
{
temp1->next->next->next->state=0;
}
else
{
temp1->next->next->next->head->front=( temp1->next->next->next->head->front+1)%10;
}
if(empty(temp1->next->next->head))
{
temp1->next->next->state=0;
}
else
{
temp1->next->next->head->front=(temp1->next->next->head->front+1)%10;
}
if(empty(temp1->next->head))
{
temp1->next->state=0;
}
else
{
temp1->next->head->front=(temp1->next->head->front+1)%10;
}
}
void m()
{
char a,c;
cout<<"请输入进程名"<<endl;
cin>>a;
cout<<"请输入设备类型"<<endl;
cin>>c;
sdt * temp1=b->next1;
// sdt * temp0=b->next1;
while(temp1!=NULL)
{
if(temp1->type==c)
break;
temp1=temp1->next1;
}
if(temp1->next->state==0)
{
if(temp1->next->next->state==0)
{
if(temp1->next->next->next->state==0)
{
temp1->next->state=1;
temp1->next->next->state=1;
temp1->next->next->next->state=1;
}
else
{
temp1->next->next->next->head->rear=(n->head->rear+1)%10;
temp1->next->next->next->head->jc[n->head->rear]='a';
}
}
else
{
temp1->next->next->head->rear=(temp1->next->next->head->rear+1)%10;
temp1->next->next->head->jc[temp1->next->next->head->r
评论0