基本操作 ①初始化 StatusInitQueue(LinkQueue&Q){//构造一个空队列Q Qfront=Qrear= (QueuePtr)malloc(sizeof(QNode)); if(!Qfront)exit(OVERFLOW);//存储分配失败 Qfront>next=NULL; returnOK; } ②入队 StatusEnQueue(LinkQueue&Q QElemTypee){//插入元素e为Q的新的队尾元素 p=(QueuePtr)malloc(sizeof(QNode)); if(!p)exit(OVERFLOW);//存储分配失败 p>data=e;p>next=NULL; Qrear>next=p;Qrear=p; returnOK; } ③出队 StatusDeQueue(LinkQueue&Q QElemType&e){ //若队列不空则删除Q的队头元素 //用e返回其值并返回OK否则返回ERROR if(Qfront==Qrear)returnERROR; p=Qfront>next;e=p>data; Qfront>next=p>next; if(Qrear==p)Qrear=Qfront; free(p);returnOK; } 返回《数据结构》考研复习精编 [] [] [] [] [] [] [] [] [] |