Advertisement
Guest User

Untitled

a guest
May 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include "iostream"
  4. #include "iostream"
  5. using namespace std;
  6.  
  7. struct spisok {
  8. int info;
  9. spisok *next, *prev;
  10. } *beginn, *en;
  11.  
  12. void add()
  13. {
  14. int in, menu1;
  15. spisok *t = new spisok;
  16. cout << "element: ";
  17. cin >> in;
  18. t->info = in;
  19. if (beginn == NULL)
  20. {
  21. beginn = en = t;
  22. t->next = t->prev = NULL;
  23. }
  24. else
  25. {
  26. while (true)
  27. {
  28. cout << "1.v nachalo ocheredi \n2.v konec ocheredi\n";
  29. cin >> menu1;
  30. switch (menu1)
  31. {
  32. case 1:
  33. t->prev = NULL;
  34. t->next = beginn;
  35. beginn->prev = t;
  36. beginn = t;
  37. return;
  38. case 2:
  39. t->next = NULL;
  40. t->prev = en;
  41. en->next = t;
  42. en = t;
  43. return;
  44. }
  45. }
  46. }
  47. }
  48.  
  49. void viev()
  50. {
  51. if (beginn == NULL)
  52. cout << "-\n\n";
  53. else
  54. {
  55. spisok *f;
  56. int menu2;
  57. while (true)
  58. {
  59. cout << "1.s nachala \n2.s konca \n";
  60. cin >> menu2;
  61. switch (menu2)
  62. {
  63. case 1:
  64. f = beginn;
  65. while (f)
  66. {
  67. cout << f->info << " ";
  68. f = f->next;
  69. }
  70. cout << endl;
  71. return;
  72. case 2:
  73. f = en;
  74. while (f)
  75. {
  76. cout << f->info << " ";
  77. f = f->prev;
  78. }
  79. cout << endl;
  80. return;
  81. }
  82. }
  83. }
  84. }
  85. void dlia_udalic()
  86. {
  87. if (beginn == NULL)
  88. cout << "-\n\n";
  89. else
  90. {
  91. spisok *f;
  92. int menu2;
  93. while (true)
  94. {
  95.  
  96. cin >> menu2;
  97. switch (menu2)
  98. {
  99. case 1:
  100. f = beginn;
  101. while (f)
  102. {
  103. cout << f->info << " ";
  104. f = f->next;
  105. }
  106. cout << endl;
  107. return;
  108. case 2:
  109. f = en;
  110. while (f)
  111. {
  112. cout << f->info << " ";
  113. f = f->prev;
  114. }
  115. cout << endl;
  116. return;
  117. }
  118. }
  119. }
  120. }
  121.  
  122. void udalic()
  123. {
  124. while (beginn)
  125. {
  126. spisok *t = beginn;
  127. beginn = beginn->next;
  128. delete t;
  129. }
  130.  
  131. }
  132.  
  133. void udalic_ne_vsio()
  134. {
  135. spisok *f = beginn;
  136. while (f)
  137. {
  138. if (f->info % 2 == 0)
  139. {
  140. if (f == beginn)
  141. {
  142. spisok *q = beginn;
  143. beginn = beginn->next;
  144. beginn->prev = NULL;
  145. f = f->next;
  146. delete q;
  147. }
  148. else if (f == en)
  149. {
  150. spisok *q = en;
  151. en = en->prev;
  152. en->next = NULL;
  153. f = f->next;
  154. delete q;
  155. }
  156. else
  157. {
  158. spisok *q = f;
  159. (f->prev)->next = f->next;
  160. (f->next)->prev = f->prev;
  161. f = f->next;
  162. delete q;
  163. }
  164. }
  165. else f = f->next;
  166. }
  167. }
  168.  
  169. void main()
  170. {
  171. setlocale(LC_CTYPE, "russian");
  172. int menu;
  173. while (true)
  174. {
  175. cout << "chto sdelac: \n1.dobaavic \n2.prosmotr \n3.udalic \n4.udalic vse \n0.zalric \n";
  176. cin >> menu;
  177. switch (menu)
  178. {
  179. case 1: add(); break;
  180. case 2: viev(); break;
  181. case 3: udalic_ne_vsio(); dlia_udalic(); break;
  182. case 4: udalic(); break;
  183. case 0: return;
  184. }
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement