stack.tex 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. \chapter{TStack}
  2. Implements stack.
  3. Usage example:
  4. \lstinputlisting[language=Pascal]{stackexample.pp}
  5. Memory complexity:
  6. Since underlaying structure is TVector, memory complexity is same.
  7. Members list:
  8. \begin{longtable}{|m{10cm}|m{5cm}|}
  9. \hline
  10. Method & Complexity guarantees \\ \hline
  11. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  12. \verb!Create! & O(1) \\ \hline
  13. \multicolumn{2}{|m{15cm}|}{Constructor. Creates empty stack.} \\ \hline\hline
  14. \verb!function Size(): SizeUInt! & O(1) \\ \hline
  15. \multicolumn{2}{|m{15cm}|}{Returns number of elements in stack.} \\\hline\hline
  16. \verb!procedure Push(value: T)! & Amortized
  17. O(1), some operations might take O(N) time, when array needs to be reallocated, but sequence of N
  18. operations takes O(N) time \\ \hline
  19. \multicolumn{2}{|m{15cm}|}{Inserts element on the top of stack.} \\\hline\hline
  20. \verb!procedure Pop()! & O(1) \\\hline
  21. \multicolumn{2}{|m{15cm}|}{Removes element from the top of stack. If stack is empty does nothing.} \\\hline\hline
  22. \verb!function IsEmpty(): boolean! & O(1) \\ \hline
  23. \multicolumn{2}{|m{15cm}|}{Returns true when stack is empty} \\\hline\hline
  24. \verb!function Top: T! & O(1) \\\hline
  25. \multicolumn{2}{|m{15cm}|}{Returns top element from stack.} \\\hline
  26. \end{longtable}