queue——问题
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string> using namespace std; typedef struct node{ int data; int qnum; struct node * next; }node; typedef struct Linkqueue{ node * front; node * rear; }Linkqueue; Linkqueue * Init(){ Linkqueue * Q; node * p; p=(node *)malloc(sizeof(node)); p->next=NULL; Q=(Linkqueue*)malloc(sizeof(Linkqueue)); Q->front=Q->rear=p; return(Q); } int enQueue(Linkqueue * Q, int data,int qnum){ node *p; p=(node *)malloc(sizeof(node)); if(!p) return -1; p->data=data; p->qnum=qnum; p->next=NULL; Q->rear->next=p; Q->rear=p; return 1; } int inQueue(node * q, int data,int qnum){ node * m; m->next=q->next; q->next=m; m->qnum=qnum; m->data=data; return 1; } int dequeue(Linkqueue * Q){ node *p; int x; if(Q->front==Q->rear) return -1; p=Q->front->next; x=p->data; if(p==Q->rear) Q->rear=Q->front; free(p); return x; } int map [5][10]; int main(){ int times; int que; Linkqueue * Q; node * m; m->next=NULL; Q->front=Q->rear=m; scanf("%d%d",×,&que); for(int i=1;i<=que;i++){ int num; scanf("%d",&num); map[i][0]=num; for(int j=1;j<=num;j++){ scanf("%d",map[i][j]); } } char s[100]; int data; int count=0; while(scanf("%s",&s)){ if(strcmp(s,"ENQUEUE")==0){ scanf("%d",data); int flag=0; for(int i=1;i<=que;i++){ for(int j=1;j<=map[i][0];j++) if(map[i][j]==data){ for(int z=1;z<=count;z++){ node *q; q=Q->front->next; if(q->qnum==i&&q->next->qnum!=i){ inQueue(q,data,i); count++; flag=1; break; } q=q->next; } if(flag==0){ enQueue(Q,data,i); count++; flag=1; break; } } if(flag==1) break; } } else if(strcmp(s,"DEQUEUE")==0){ int x; x=dequeue(Q); count--; printf("%d\n",x); } else if (strcmp(s,"STOP")==0) break; } }