Advertisement
Guest User

Untitled

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