From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- public/arraystack.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 public/arraystack.h (limited to 'public/arraystack.h') diff --git a/public/arraystack.h b/public/arraystack.h new file mode 100644 index 0000000..907fb61 --- /dev/null +++ b/public/arraystack.h @@ -0,0 +1,69 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// +//----------------------------------------------------------------------------- +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef ARRAYSTACK_H +#define ARRAYSTACK_H +#pragma once + +#include +#include "List.h" + +template class ArrayStack +{ +protected: + T *data; + int m_stackDepth; + int m_maxNumElements; + +public: + ArrayStack( int maxNumElements ) + { + data = new T[maxNumElements]; + m_maxNumElements = maxNumElements; + m_stackDepth = 0; + assert( data ); + } + + void Push( T elem ) + { + data[m_stackDepth++] = elem; + if( m_stackDepth > m_maxNumElements ) + { + printf( "ArrayStack overflow\n" ); + assert( 0 ); + } + } + + T Pop( void ) + { + if( m_stackDepth == 0 ) + { + printf( "ArrayStack underflow\n" ); + assert( 0 ); + } + return data[--m_stackDepth]; + } + + bool IsEmpty() + { + return ( m_stackDepth == 0 ); + } + + int GetDepth() + { + return m_stackDepth; + } +}; + + +#endif // ARRAYSTACK_H -- cgit v1.2.3