⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cqueue.h

📁 大二半年的数据结构上机实验。包括链表
💻 H
字号:
#ifndef _CQueue_H_
#define _CQueue_H_
#include<iostream.h>
#include<stdlib.h>
#define MaxQueueSize 20

template <class T>
class CQueue{
  private:
    T data[MaxQueueSize];
    int front;
    int rear;
    int count;
    
  public:
    CQueue(void)
    {front=rear=0;count=0;};
    ~CQueue(void){};
    void EnQueue(const T &item);
    T DelQueue(void);
    T GetFront(void) const;
    int NotEmpty(void) const
    {return count!=0;};
    void Printlist();
};
#endif

template<class T>
void CQueue<T>::EnQueue(const T & item)
{
  if(count>0&&front==rear)
   {cout<<"队列已满"<<endl;
    exit(0);
   }
   data[rear]=item;
   rear=(rear+1)%MaxQueueSize;
   count++;
}

template<class T>
T CQueue<T>::DelQueue(void)
{
  if(count==0)
	{cout<<"队列空"<<endl; 
	 exit(0);
	}
   T temp=data[front];
   front=(front+1)%MaxQueueSize;
   count--;
   return temp;
}

template<class T>
T CQueue<T>::GetFront(void) const
{
	if(count==0)
	{
		cout<<"队列空"<<endl;
		exit(0);
	}
	return data[front];
}

template<class T>
void CQueue<T>::Printlist()
{int i;
 i=front;
  if(count==0)
	{
		cout<<"队列空"<<endl;
		exit(0);
	}
while(i!=rear)
 {cout<<data[i]<<endl;
  i++;}
} 
   
   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -