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

📄 adapter.cpp

📁 设计模式实例: 适配器(Adapter)模式源代码
💻 CPP
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -