如何实现循环队列

2020-01-06 13:24:56王旭
  • printf("%5dt", i);   PrintElem(Q.base[i]);  
  • printf("n");   }  
  • }   printf("--- view end ---n");  
  • }   ******/ //TODO: 删除此行以便使用QueueView()  
  •   //取消ElemType的默认定义,以免影响其它部分  
  • #ifdef USE_DEFAULT_ELEMTYPE   #undef ElemType  
  • #undef USE_EFAULT_ELEMTYPE   #endif  
  •   #endif //SQQUEUE_H_INCLUDED  
  •   #include <stdio.h>  
  • #include <stdlib.h>   #include "sqqueue.h"  
  •   //初始化系统  
  •    
  • void Finalize(SqQueue &q);    
  • ////////////////////////////////////////////   //主程序  
  • int main()   {  
  • SqQueue q; //循环队列   int x;  
  •   //系统初始化  
  • InitQueue(q);   printf("数据元素进队列,以0结束");  
  • scanf("%d",&x);   while(x!=0){  
  • EnQueue(q,x);   scanf("%d",&x);  
  • }   printf("n队列元素的个数");  
  •   printf("%d",QueueLength(q));  
  •    
  • printf("n头元素是:");   if(!QueueEmpty(q)){  
  • if(GetHead(q,x)==OK)   printf("%d",x);  
  • }    
  •   printf("n出队列,先进先出");  
  • if( DeQueue(q,x)==OK)   printf("%d",x);  
  • printf("n此时的对头是:");   if(!QueueEmpty(q)){  
  • if(GetHead(q,x)==OK)   printf("%dn",x);  
  • }    
  • }