fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class Item>
  5. class PQ{
  6. private:
  7. Item *pq; /*Массив элементов*/
  8. int n; /*Текущее оличество элементов в очереди*/
  9. int max; /*Максимальное количество элементов в очереди*/
  10. public:
  11. PQ(int max){
  12. pq = new Item[max];
  13. n = 0;
  14. this->max = max;
  15. }
  16.  
  17. ~PQ(){
  18. delete[] pq;
  19. }
  20.  
  21. int empty() const{ return n == 0; }
  22.  
  23. /*Функция добавления элемента, поддерживающая упорядоченность массива*/
  24. void insert(Item item){
  25. if(n+1 < max){
  26. int location = n - 1;
  27.  
  28. while(location >= 0 && pq[location] > item){
  29. pq[location + 1] = pq[location];
  30. location = location - 1;
  31. }
  32. pq[location + 1] = item;
  33. n++;
  34. }
  35. //pq[n++] = item;
  36. }
  37.  
  38. };
  39.  
  40. int main() {
  41. // your code goes here
  42. return 0;
  43. }
Success #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty