fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Heap
  5. {
  6. public:
  7. Heap(int max_size)
  8. {
  9. t=new int[max_size+1];
  10. current_size=0;
  11. };
  12.  
  13. //**********************************************
  14. void insert_int(int x)
  15. {
  16. t[++current_size]=x;
  17. GoUp();
  18. }
  19. //**********************************************
  20. void GoUp()
  21. {
  22. int temp=t[current_size];
  23. int n=current_size;
  24.  
  25. while((n!=1) && (t[n/2]<=temp))
  26. {
  27. t[n]=t[n/2];
  28. n=n/2;
  29. }
  30. t[n]=temp;
  31. }
  32. //**********************************************
  33. int get_first()
  34. {
  35. int x=t[1];
  36. t[1]=t[current_size--];
  37.  
  38. GoDown();
  39. return x;
  40. }
  41. //**********************************************
  42. void GoDown()
  43. {
  44. int i=1;
  45. while(true)
  46. {
  47. int p=2*i;
  48. if(p>current_size)
  49. break;
  50. if(p+1<=current_size)
  51. if(t[p]<t[p+1])
  52. p++;
  53. if(t[i]>=t[p])
  54. break;
  55.  
  56. int temp=t[p];
  57. t[p]=t[i];
  58. t[i]=temp;
  59.  
  60. i=p;
  61. }
  62. }
  63.  
  64.  
  65. private:
  66. int *t;
  67. int current_size;
  68. };
  69.  
  70. int main()
  71. {
  72. Heap S(13);
  73. cout << "Fajnie" << endl;
  74. return 0;
  75. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
Fajnie