adapter.cpp

来自「设计模式实例: 适配器(Adapter)模式源代码」· C++ 代码 · 共 65 行

CPP
65
字号
// Adapter.cpp: implementation of the Adapter class.
//
//////////////////////////////////////////////////////////////////////

#include "Adapter.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Adapter::Adapter()
{
	m_pStack=new Stack;
}

Adapter::Adapter(Stack *p)
{
	m_pStack=p;
}


Adapter::~Adapter()
{
	if(m_pStack!=NULL)
		delete m_pStack;
}


void Adapter::EnQueue(int a)
{
	m_pStack->Push(a);
}
int Adapter::DeQueue()
{
		
	if(IsEmpty())
	{
		return 0;
	}
	else
	{
		int value;
		int length=m_pStack->GetLength();
		int *temp=new int[length];
		int i=0;
		while(m_pStack->IsEmpty()==false)
		{
			temp[i++]=m_pStack->Pop();
		}
		value=temp[i-1];
		i=i-2;
		for(;i>=0;i--)
			m_pStack->Push(temp[i]);
		delete temp;
		return value;
	}
}
bool Adapter::IsEmpty()
{
	return m_pStack->IsEmpty();
}
bool Adapter::IsFull()
{
	return m_pStack->IsFull();
}

⌨️ 快捷键说明

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