priorityqueue.tex 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. \chapter{TPriorityQueue}
  2. Implements priority queue. It's container which allow insertions of elements and then retrieval of
  3. the biggest one.
  4. For specialization it needs two arguements. First is the type T of stored element. Second one is type
  5. comparator class, which should have class function \verb!c(a,b: T):boolean! which return true, when
  6. a is stricly less then b (or in other words, a should be poped out after b).
  7. Usage example:
  8. \lstinputlisting[language=Pascal]{priorityqueueexample.pp}
  9. Memory complexity:
  10. Since underlaying structure is TVector, memory complexity is same.
  11. Members list:
  12. \begin{longtable}{|m{10cm}|m{5cm}|}
  13. \hline
  14. Method & Complexity guarantees \\ \hline
  15. \multicolumn{2}{|m{15cm}|}{Description} \\ \hline\hline
  16. \verb!Create! & O(1) \\ \hline
  17. \multicolumn{2}{|m{15cm}|}{Constructor. Creates empty priority queue.} \\ \hline\hline
  18. \verb!function Size(): SizeUInt! & O(1) \\ \hline
  19. \multicolumn{2}{|m{15cm}|}{Returns number of elements in priority queue.} \\\hline\hline
  20. \verb!procedure Push(value: T)! & Amortized
  21. O(lg N), some operations might take O(N) time, when underlaying array needs to be reallocated, but sequence of N
  22. operations takes O(N lg N) time. \\ \hline
  23. \multicolumn{2}{|m{15cm}|}{Inserts element at the back of queue.} \\\hline\hline
  24. \verb!procedure Pop()! & O(lg N) \\\hline
  25. \multicolumn{2}{|m{15cm}|}{Removes the biggest element from queue. If queue is empty does nothing.} \\\hline\hline
  26. \verb!function IsEmpty(): boolean! & O(1) \\ \hline
  27. \multicolumn{2}{|m{15cm}|}{Returns true when queue is empty.} \\\hline\hline
  28. \verb!function Top: T! & O(1) \\\hline
  29. \multicolumn{2}{|m{15cm}|}{Returns the biggest element from queue.} \\\hline
  30. \end{longtable}