Bob103

очередь

Jun 22nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include "queue.h"
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream in("input.txt");
  10. ofstream out("output.txt");
  11. Queue<int> getNumb;
  12. int x,i;
  13.  
  14. cin >> x;
  15.  
  16.  
  17. while (in>>i)
  18. {
  19. getNumb.Put(i);
  20. }
  21.  
  22. while (!getNumb.Empty())
  23. {
  24.  
  25. if (x != getNumb.Get())
  26. {
  27. out << getNumb.Get() << " ";
  28. }
  29. in.close();
  30. out.close();
  31. return 0;
  32. }
  33. }
  34.  
  35.  
  36. using namespace std;
  37.  
  38. template <class Item>
  39. class Queue
  40. {
  41. private:
  42. struct Element
  43. {
  44. Item inf;
  45. Element *next;
  46. Element(Item x) : inf(x), next(0) {}
  47. };
  48. Element *head, *tail;
  49. public:
  50. Queue() : head(0), tail(0) {}
  51. bool Empty()
  52. {
  53. return head == 0;
  54. }
  55. Item Get()
  56. {
  57. if (Empty())
  58. {
  59. return 0;
  60. }
  61. else
  62. {
  63. Element *t = head;
  64. Item i = t->inf;
  65. head = t->next;
  66. if (head == 0)
  67. tail = 0;
  68. delete t;
  69. return i;
  70. }
  71. }
  72. void Put(Item data)
  73. {
  74. Element *t = tail;
  75. tail = new Element(data);
  76. if (!head)
  77. {
  78. head = tail;
  79. }
  80. else
  81. {
  82. t->next = tail;
  83. }
  84. }
  85. };
Advertisement
Add Comment
Please, Sign In to add comment