Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// \file
  3. /// \brief Int Stack class definition
  4. /// \author Sergey Shershakov
  5. /// \version 0.2.0
  6. /// \date 23.01.2017
  7. /// This is a part of the course "Algorithms and Data Structures"
  8. /// provided by the School of Software Engineering of the Faculty
  9. /// of Computer Science at the Higher School of Economics.
  10. ///
  11. /// Implementations for the methods declared in the classes below must be put
  12. /// in corresponding module named int_stack.cpp.
  13. ///
  14. /// Initially created by Sergey on 24.01.2016.
  15. /// See http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html for Doxygen documenting
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////
  18.  
  19.  
  20.  
  21.  
  22. #ifndef STACKMACHINE_INT_STACK_H
  23. #define STACKMACHINE_INT_STACK_H
  24.  
  25. #include <stddef.h> // need fo size_t
  26.  
  27.  
  28.  
  29. namespace xi {
  30.  
  31.  
  32. /** Declares a stack of integers.
  33. */
  34. class IntStack {
  35. public:
  36. // const
  37. static const int STACK_SIZE = 1024; ///< Defines a default value for maximum number of stack elements
  38.  
  39. public:
  40. // Constructors
  41. IntStack(size_t sz = STACK_SIZE); ///< Default constructor
  42. ~IntStack();
  43.  
  44. private:
  45. // Большая тройка.
  46. // Не нужно реализовывать, мы просто запрещаем пользоваться оп и кк извне.
  47. IntStack(const IntStack& copy);
  48. IntStack& operator=(const IntStack &other);
  49.  
  50. public:
  51. //----<Main ADT interface>----
  52.  
  53. /** Pushes a given element onto the stack.
  54. *
  55. * If no more elements can be placed onto the stack due to its overflow an std::logic_error is thrown.
  56. */
  57. void push(int el);
  58.  
  59. /** Pops an element from the stack and returns its value.
  60. *
  61. * If no elements stored in the stack, a std::logic_error is thrown.
  62. */
  63. int pop();
  64.  
  65. /** Looks up an element from the top of the stack and returns its value.
  66. *
  67. * If no elements stored in the stack, a std::logic_error is thrown.
  68. */
  69. int top();
  70.  
  71. /** Clears the stack and makes it empty.
  72. *
  73. * Often named as makeEmpty or similar
  74. */
  75. void clear();
  76.  
  77. public:
  78. // Non classic ADT helper methods
  79.  
  80. /** Returns true if the stack is empty, false otherwise */
  81. bool isEmpty() const;
  82.  
  83. /** Returns true if the stack is full, false otherwise */
  84. bool isFull() const;
  85.  
  86.  
  87. protected:
  88. //int _stack[STACK_SIZE]; ///< Stack elements as an fixed size array
  89. int* _stack; ///< Stack as a dynamic array
  90. size_t _ssize; ///< Actual stack size
  91. size_t _head; ///< Stack head
  92. }; // class IntStack
  93.  
  94.  
  95. } // namespace xi
  96.  
  97. #endif //STACKMACHINE_INT_STACK_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement