fork(2) download
  1. #ifndef QUEUE_H
  2. #define QUEUE_H
  3.  
  4. #include <string>
  5. #include <iostream>
  6.  
  7.  
  8. class Hikkey{
  9. private:
  10. std::string name;
  11. public:
  12. virtual void fuck() = 0;
  13. };
  14.  
  15. class AttentionWhore : public Hikkey{
  16. private:
  17. std::string name;
  18. public:
  19. AttentionWhore(std::string pogonyalo){ name = pogonyalo; }
  20. virtual void fuck(){
  21. std::cout << name << " vieban i obossan" << std::endl;
  22. }
  23. void porvatsya(){ std::cout << name << " porvalsya" << std::endl; }
  24. };
  25.  
  26.  
  27.  
  28. template<class T>
  29. class NodeQueue
  30. {
  31. public:
  32. NodeQueue():head(0), tail(0){}
  33.  
  34. ~NodeQueue()
  35. {
  36. while(head)
  37. {
  38. tail=head->next;
  39. delete head;
  40. head=tail;
  41. }
  42. }
  43.  
  44. void enqueue(T val)
  45. {
  46. Node* Temp=new Node;
  47. Temp->elem=val;
  48. if(head==0)
  49. {
  50. head=Temp;
  51. tail=Temp;
  52. return;
  53. }
  54. tail->next=Temp;
  55. tail=Temp;
  56. }
  57.  
  58. void nahooy()
  59. {
  60. if (empty())
  61. {
  62. throw std::string("Queue is empty");
  63. }
  64. Node* delPtr=head;
  65. head=head->next;
  66. delete delPtr;
  67. }
  68.  
  69. const T& front() const
  70. {
  71. if (empty())
  72. {
  73. throw std::string("Queue is empty");
  74. }
  75. return head->elem;
  76. }
  77.  
  78. void print() const
  79. {
  80. if (empty())
  81. {
  82. throw std::string("Queue is empty");
  83. }
  84. for(Node* ptr=head; ptr!=0; ptr=ptr->next)
  85. std::cout<<ptr->elem<<' ';
  86. std::cout<<'\n';
  87. }
  88.  
  89. bool empty() const
  90. {
  91. return head==0;
  92. }
  93. private:
  94. struct Node
  95. {
  96. Node():next(0), elem(0)
  97. {
  98. }
  99. Node* next;
  100. T elem;
  101. };
  102. Node* head;
  103. Node* tail;
  104. };
  105.  
  106. #endif // QUEUE_H
  107.  
  108. int main()
  109. {
  110.  
  111. std::string whores[] = {"Madina", "Ponos", "Yakooy", "ID25", "Kotomi", "Smith", "Console", "Rugged", "Ba4mo", "Tolyan", "Elsa", "Stoocka", "Chaos", "Barebuh", "Sento"};
  112. NodeQueue<AttentionWhore*> mrazy;
  113.  
  114. for(int i = 0; i < 15; i++)
  115. mrazy.enqueue(new AttentionWhore(whores[i]));
  116. for(int i = 0; i < 15; i++){
  117. mrazy.front()->fuck();
  118. mrazy.front()->porvatsya();
  119. mrazy.nahooy();
  120. std::cout << std::endl;
  121. }
  122. return 0;
  123. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
Madina vieban i obossan
Madina porvalsya

Ponos vieban i obossan
Ponos porvalsya

Yakooy vieban i obossan
Yakooy porvalsya

ID25 vieban i obossan
ID25 porvalsya

Kotomi vieban i obossan
Kotomi porvalsya

Smith vieban i obossan
Smith porvalsya

Console vieban i obossan
Console porvalsya

Rugged vieban i obossan
Rugged porvalsya

Ba4mo vieban i obossan
Ba4mo porvalsya

Tolyan vieban i obossan
Tolyan porvalsya

Elsa vieban i obossan
Elsa porvalsya

Stoocka vieban i obossan
Stoocka porvalsya

Chaos vieban i obossan
Chaos porvalsya

Barebuh vieban i obossan
Barebuh porvalsya

Sento vieban i obossan
Sento porvalsya