这个题有点小坑,头插尾插先挪动指针还是先插入不一样,当然这个双端队列是在是循环队列的基础上,循环队列具体不说了。删除时,头部是删除的当前指针的值,而尾部删除是删除前移的值
bool Push( ElementType X, Deque D )
{if((D->Rear + 1) % D->MaxSize == D->Front){return false;}D->Front = (D->Front + D->MaxSize - 1) % D->MaxSize;D->Data[D->Front] = X;return true;}
ElementType Pop( Deque D )
{if(D->Rear == D->Front){return ERROR;}ElementType n = D->Data[D->Front];D->Front = (D->Front + 1) % D->MaxSize;return n;}
bool Inject( ElementType X, Deque D )
{if((D->Rear + 1) % D->MaxSize == D->Front){return false;}D->Data[D->Rear] = X;D->Rear = (D->Rear + 1) % D->MaxSize;return true;}
ElementType Eject( Deque D )
{if(D->Rear == D->Front){return ERROR;}else{D->Rear = (D->Rear + D->MaxSize-1 ) % D->MaxSize;return D->Data[D->Rear];}
}