Bob103

стэк

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