Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // ЭКЗ БИЛЕТ ЧАЕВСКОГО.cpp: определяет точку входа для консольного приложения.
  2. //Создать стеки для 7 элементов.Удалить все положительные и очистить память
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. struct stack {
  10. int inf;
  11. stack *next;
  12. };
  13.  
  14. stack* AddNewStack(stack*&);
  15. void ReadStack(stack*&);
  16. stack* Delete(stack*&);
  17.  
  18.  
  19. int main()
  20. {
  21. stack*head = NULL, *temp;
  22. cout << "Vvedite colvo elementov v steke" << endl;
  23. int n;
  24. cin >> n;
  25. for (int i = 1; i <= n; i++)
  26. {
  27. AddNewStack(*&head);
  28. }
  29. temp = head;
  30. cout << "Stek: " << endl;
  31. ReadStack(*&head);
  32. cout << endl;
  33.  
  34. head = temp;
  35. stack* Zadanie(stack*&head);
  36.  
  37. head = temp;
  38. cout << "Noviy Stek: " << endl;
  39. ReadStack(*&head);
  40. cout << endl;
  41.  
  42.  
  43.  
  44.  
  45.  
  46. system("pause");
  47. return 0;
  48. }
  49.  
  50. stack* AddNewStack(stack*&head)
  51. {
  52. stack*element = new stack;
  53. element->next = head;
  54. cin >> element->inf;
  55. head=element;
  56. return head;
  57. }
  58.  
  59. void ReadStack(stack*&head)
  60. {
  61. stack*tmp = head;
  62. while (head != NULL)
  63. {
  64. cout << head->inf << " ";
  65. head = head->next;
  66. }
  67. head = tmp;
  68. cout << endl;
  69. return;
  70. }
  71.  
  72. stack* Delete(stack*&head)
  73. {
  74. while (head != NULL)
  75. {
  76. stack*tmp = head;
  77. head = head->next;
  78. delete tmp;
  79. }
  80. delete head;
  81. return NULL;
  82. }
  83.  
  84. stack* Zadanie(stack*&head)
  85. {
  86. while (head != NULL)
  87. {
  88. if (head->inf > 0)
  89. {
  90. stack*tmp = head;
  91. head = head->next;
  92. delete tmp;
  93. }
  94. else
  95. {
  96. head = head->next;
  97. }
  98. }
  99. return NULL;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement