#include "global.h"
#include "cstack.h"
#include "cmemory.h"
#include <stdlib.h>

CStack::CStack()
{
	mem = _NEW(CMemory());
	top = 0;
}

CStack::~CStack()
{
	_DELETE(mem);
}

bool CStack::Empty()
{
	if (!top)
		return true;
	else
		return false;
}

void CStack::Push(DWORD item)
{
	if ((mem->GetSize()/4) == top)
		mem->AddData(&item, 4);
	else
		((DWORD*)mem->GetPointer())[top] = item;
	top++;
}

DWORD CStack::Top()
{
	if (!top)
	{
#ifdef _DEBUG
		::MessageBox(NULL, "Prázdny stack", "CStack::Top", MB_ICONSTOP|MB_OK);
#endif
		app.abort();
	}
	return ((DWORD*)mem->GetPointer())[top-1];
}

DWORD CStack::Pop()
{
	if (!top)
	{
#ifdef _DEBUG
		::MessageBox(NULL, "Prázdny stack", "CStack::Pop", MB_ICONSTOP|MB_OK);
#endif
		app.abort();
	}
	top--;
	return ((DWORD*)mem->GetPointer())[top];
}