#define NULL 0 typedef struct LNode{ int name; int x; int time; int y; struct LNode *next; }LNode,*LinkList; createList(int n){ 创建就绪对列 int i=0; LinkList L,p; L=(LinkList)malloc(sizeof(LNode)); L->next=NULL; for(i=n;i>0;--i){ p=(LinkList)malloc(sizeof(LNode)); scanf("%d",&p->name); printf("\n"); scanf("%d",&p->x); printf("\n"); scanf("%d",&p->time); printf("\n"); p->y=1; p->next=L->next; L->next=p; } return(L); } BlockList(LinkList *LA,LinkList *LB){ 阻塞一个进程 lb为阻塞队列 LNode *pa,*pb,*pd; int m=0,n=0,a=0; pa=(*LA)->next; pd=LA; pb=(*LB)->next; printf("input the name of block jincheng:"); if(pa==NULL) printf("ERROR!"); else { printf("input the name of block jincheng:"); scanf("%d",&a); printf("\n"); while(pa){ if(pa->name==a){ pd->next=pa->next; pa->next=pb->next; pb->next=pa; m=1; break; } else{pd=pa; pa=pa->next;} } while(pb){ if(pb->name==a) { printf("Already!"); n=1; break; } else pb=pb->next; } if(!(m||n)) printf("NO FOUND!"); } }
WakeupList(LinkList *LA,LinkList *LB){ 唤醒 int m=0,n=0,a=0; LNode *pa,*pb; pa=(*LA)->next; pb=(*LB)->next; printf("input the name of wakeup jincheng:"); scanf("%d",&a); printf("\n"); if(!pb) printf("error!!!\n"); else {while(pb!=NULL) {if(pb->name==a) {pb->next=pa->next; pa->next=pb; pb->y=1; m=1; break; } else pb=pb->next;} while(pa){ if(pa->name==a) {printf("Already!!!"); n=1; break;} else pa=pa->next; } if((m||n)) printf("NO FOUND!!!\n"); } }
EndList(LinkList *LA,LinkList *LB){ 结束一个进程 int m=0,n=0,a=0; LNode *pa,*pb,*pc,*pd; pc=LA; pd=LB; pa=(*LA)->next; pb=(*LB)->next; printf("input the name of end jincheng:"); scanf("%d",&a); printf("\n"); if(!(pa||pb)) printf("ERROR!!!\n"); else{ while(pa){ if(pa->name==a) {pc->next=pa->next; m=1; break;} else{ pc=pa; pa=pa->next;} } while(pb){ if(pb->name==a) {pd->next=pb->next; n=1; break;} else { pd=pb; pb=pb->next;} } if(!(m||n)) printf("NO FOUND!!!\n"); } }
prnList(LinkList *La,LinkList *Lb){ 输出 LNode *pa,*pb; pa=(*La)->next; pb=(*Lb)->next; printf("jiuxu:\n"); if(!pa) printf("Empty!\n"); while(pa){ printf("name:"); printf("%d\n",pa->name); printf("x:"); printf("%d\n",pa->x); printf("time:"); printf("%d\n",pa->time); printf("y:"); printf("%d\n",pa->y); pa=pa->next; } printf("block:\n"); if(!pb) printf("Empty!!\n"); while(pb){ printf("name:"); printf("%d\n",pb->name); printf("x:"); printf("%d\n",pb->x); printf("time:");printf("%d\n",pb->time); printf("y:"); printf("%d\n",pb->y); pb=pb->next; } }
main(){ int n=0,i=1,c=0,m=0; LinkList LA,LB; LA=(LinkList)malloc(sizeof(LNode)); LA->next=NULL; LB=(LinkList)malloc(sizeof(LNode)); LB->next=NULL; printf(" start\n"); printf(" system menu\n"); printf(" 1......create\n"); printf(" 2......block\n"); printf(" 3......wakeup\n") ; printf(" 4......End\n"); printf(" 5......prn\n"); printf(" 0......exit\n"); while(i){ printf("please select: "); scanf("%d",&n); printf("\n"); if(n<0||n>5){ printf("please input 0 to 5!!!\n"); scanf("%d",n); printf("\n");} switch(n){case 0: i=0;break; case 1:{ printf("intput the number of list:"); scanf("%d",&m); printf("\n"); LA=createList(m); LB=createList(0); break;} case 2: BlockList(&LA,&LB);break; case 3: WakeupList(&LA,&LB);break; case 4: EndList(&LA,&LB);break; case 5: prnList(&LA,&LB);break; } } } 这是我自己写的,帮我看看在调用BlockList之后输出的结果为什么不正确!!!是不是调用之后返回的问题!!!