Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef ARRAYSTACK_H
  14. #define ARRAYSTACK_H
  15. #pragma once
  16. #include <assert.h>
  17. #include "List.h"
  18. template <class T> class ArrayStack
  19. {
  20. protected:
  21. T *data;
  22. int m_stackDepth;
  23. int m_maxNumElements;
  24. public:
  25. ArrayStack( int maxNumElements )
  26. {
  27. data = new T[maxNumElements];
  28. m_maxNumElements = maxNumElements;
  29. m_stackDepth = 0;
  30. assert( data );
  31. }
  32. void Push( T elem )
  33. {
  34. data[m_stackDepth++] = elem;
  35. if( m_stackDepth > m_maxNumElements )
  36. {
  37. printf( "ArrayStack overflow\n" );
  38. assert( 0 );
  39. }
  40. }
  41. T Pop( void )
  42. {
  43. if( m_stackDepth == 0 )
  44. {
  45. printf( "ArrayStack underflow\n" );
  46. assert( 0 );
  47. }
  48. return data[--m_stackDepth];
  49. }
  50. bool IsEmpty()
  51. {
  52. return ( m_stackDepth == 0 );
  53. }
  54. int GetDepth()
  55. {
  56. return m_stackDepth;
  57. }
  58. };
  59. #endif // ARRAYSTACK_H