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

📄 deque.h

📁 数据结构c++语言描述 Borland C++实现
💻 H
字号:

// header file deque.h
// formula-based deque derived from the class Queue
// data members of Queue are protected (not private)
#ifndef Deque_
#define Deque_

#include<stdlib.h>
#include<iostream.h>
#include "cqueue.h"
#include "xcept.h"

template<class T>
class Deque : protected Queue<T>
{
   public:
      Deque(int MaxDequeSize = 10)
         : Queue<T> (MaxDequeSize) {}
      bool IsEmpty() const
           {return Queue<T>::IsEmpty();}
      bool IsFull() const
           {return Queue<T>::IsFull();}
      T Left() const
        {return First();}
      T Right() const
        {return Last();}
      Deque<T>& AddLeft(const T& x);
      Deque<T>& AddRight(const T& x)
                {Add(x); return *this;}
      Deque<T>& DeleteLeft(T& x)
                {Delete(x); return *this;}
      Deque<T>& DeleteRight(T& x);
};

template<class T>
Deque<T>& Deque<T>::AddLeft(const T& x)
{// Add x to left end of deque.
   // first see if there is space
   if (IsFull()) throw NoMem();

   // put x counterclockwise from current
   // leftmost element
   queue[front] = x;

   // move front counterclockwise
   if (front == 0) front = MaxSize - 1;
   else front--;

   return *this;
}

template<class T>
Deque<T>& Deque<T>::DeleteRight(T& x)
{// Delete rightmost element and put in x.

   // first make sure there is a last element
   if (IsEmpty()) throw OutOfBounds();

   // save last element in x
   x = queue[rear];

   // move rear counterclockwise
   if (rear == 0) rear = MaxSize - 1;
   else rear--;

   return *this;
}

#endif

⌨️ 快捷键说明

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