Advertisement
Guest User

Untitled

a guest
May 16th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct tlist
  7. {
  8. int inf;
  9. tlist *a;
  10. };
  11.  
  12. void addstack(tlist **sp, int inf)
  13. {
  14. tlist *spt = new tlist;
  15. spt->inf = inf;
  16. spt->a = sp;
  17. }
  18.  
  19.  
  20. void delstack(tlist **sp)
  21. {
  22. tlist *spt;
  23. //int inf;
  24. while (sp != NULL)
  25. {
  26. spt = sp;
  27. //inf = ;
  28. cout << sp->inf << endl;
  29. sp = sp->a;
  30. delete spt;
  31. }
  32. system("pause");
  33. }
  34.  
  35. void readstack(tlist *sp)
  36. {
  37. while (sp)
  38. {
  39. cout << sp->inf << " ";
  40. sp = sp->a;
  41. }
  42. cout << endl;
  43. system("pause");
  44. }
  45.  
  46.  
  47. int main()
  48. {
  49. tlist *sp;
  50. sp = NULL;
  51. int n, k;
  52. cout << "VVEDI CHISLO ELEMENTOV V STEKE: ";
  53. cin >> n;
  54. if (n < 1) return 0;
  55. for (int i = 0; i < n; i++)
  56. {
  57. cout << "VVEDI CHISLO: ";
  58. cin >> k;
  59. addstack(&sp, k);
  60. }
  61. cout << "VVEDYNIY STEK: ";
  62. readstack(sp);
  63. tlist *p, *t;
  64. //p = sp;
  65. //t = NULL;
  66. tlist*tmp = new tlist;
  67. tmp->a = sp;
  68. while (tmp!=NULL&&tmp->a != NULL) {
  69. if (tmp->a->inf % 2 == 0) {
  70. t=tmp->a
  71. tmp->a = tmp->a->a;
  72. delete t;
  73. }
  74.  
  75. }
  76.  
  77. /*while (p)
  78. {
  79. if (p->inf % 2 == 0)
  80. {
  81. if (p == sp)
  82. {
  83. sp = sp->a;
  84. delete p;
  85. p = sp;
  86. }
  87. else
  88. {
  89. t->a = p->a;
  90. delete p;
  91. p = t->a;
  92. }
  93. }
  94. else
  95. {
  96. t = p;
  97. p = p->a;
  98. }
  99. }*/
  100. cout << "NOVIY STACK: ";
  101. readstack(sp);
  102. delstack(&sp);
  103. return 0;
  104. system("pause");
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement