fork download
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. using namespace std;
  7. struct city
  8. {
  9. string name_f;
  10. string name_p;
  11. string date;
  12. string genre;
  13. struct city *next;
  14. struct city *previous;
  15. };
  16. city *head=NULL;
  17. city *last=NULL;
  18. city *current=NULL; //текущий элемент
  19. city *temp=NULL;
  20. city *newList=NULL ;
  21. /* Процедура создания добавления в список */
  22. void add_name(string namef_,string namep_, string date_, string genre_)
  23. {
  24. if(head!=NULL)
  25. {
  26. newList=new city;
  27. newList->name_f=namef_;
  28. newList->name_p=namep_;
  29. newList->date=date_;
  30. newList->genre=genre_;
  31. newList->next=NULL;
  32. newList->previous=current;
  33. current->next=newList;
  34. last=newList;
  35. current=newList;
  36. }
  37. else
  38. {
  39. newList=new city;
  40. newList->name_f=namef_;
  41. newList->name_p=namep_;
  42. newList->date=date_;
  43. newList->genre=genre_;
  44. head=newList;
  45. newList->next=NULL;
  46. newList->previous=NULL;
  47. current=newList;
  48. last=head;//Забыли установить!!!
  49. }
  50. }
  51.  
  52. /* Процедура удаления узла */
  53. void delete_unit()
  54. { newList=head;
  55. if(newList == head->next)
  56. {
  57. delete head; //удаление элемента
  58. head=NULL;
  59. }
  60. else
  61. {
  62. head=head->next;
  63. head->previous=NULL;
  64. delete newList;
  65. }
  66. }
  67. /* Процедура вывода списка слева направо */
  68. int count_L()
  69. {
  70. int count;
  71. newList = head;
  72. if(newList == NULL)
  73. {
  74. count = 0;
  75. }
  76. else
  77. {
  78. while(newList != NULL)
  79. {
  80. count=count+1;
  81. newList = newList->next;
  82. }
  83. }
  84. return count;
  85. }
  86. void show_list(void)
  87. {
  88. struct city *info;
  89. info = head;
  90. while(info)
  91. {
  92. cout<<info->name_f<<"\t";
  93. cout<<info->name_p<<"\t";
  94. cout<<info->date<<"\t";
  95. cout<<info->genre<<"\t";
  96. cout<<"\n";
  97. info = info->next;
  98. }
  99. }
  100. /* Процедура вывода списка справа налево */
  101. void show_list_1(void)
  102. {
  103. struct city *info;
  104. info = last;
  105. while(info)
  106. {
  107. cout<<info->name_f<<"\t";
  108. cout<<info->name_p<<"\t";
  109. cout<<info->date<<"\t";
  110. cout<<info->genre<<"\t";
  111. cout<<"\n";
  112. info = info->previous;
  113. }
  114. }
  115.  
  116. /* Тело основной программы */
  117. int main(void)
  118. {
  119. setlocale(LC_ALL,"Russian");
  120. SetConsoleCP(1251);
  121. SetConsoleOutputCP(1251);
  122. string name_f;
  123. string name_p;
  124. string date;
  125. string genre;
  126. int key=-1;
  127. while(key)
  128. {
  129. cout<<"1. Enter name\n";
  130. cout<<"2. Delete name\n";
  131. cout<<"3. Show names\n";
  132. cout<<"4. Show names from end\n";
  133. cout<<"0. Exit\n";
  134. cin>>key;
  135. switch (key)
  136. {
  137. case 1:
  138. {
  139. cout<<"Введите название театра\n";
  140. cin>>name_f;
  141. cout<<"Ведите название представления\n";
  142. cin>>name_p;
  143. cout<<"Ведите дату представления\n";
  144. cin>>date;
  145. cout<<"Ведите жанр представления\n";
  146. cin>>genre;
  147. add_name(name_f,name_p,date,genre);
  148. break;
  149. }
  150. case 2:
  151. {
  152. int n = count_L();
  153. if(n == 0)
  154. {
  155. cout<<"Невозможноу удалить элементы в стеке 0 элементов";
  156. }
  157. else if (n == 1)
  158. {
  159. cout<<"Невозможноу удалить элементы в стеке 1 элемент";
  160. }
  161. else if (n > 2)
  162. {
  163. delete_unit();
  164. delete_unit();
  165. }
  166. break;
  167. }
  168. case 3:
  169. {
  170. cout<<"Список с лева на право\n";
  171. show_list();
  172. break;
  173. }
  174. case 4:
  175. {
  176. cout<<"Список с права на лево\n";
  177. show_list_1();
  178. break;
  179. }
  180. case 0:
  181. {
  182. cout<<"Пока\n";
  183. getch();
  184. break;
  185. }
  186. default:
  187. {
  188. cout<<"Error\n";
  189. getch();
  190. break;
  191. }
  192. if (key==0) break;
  193. }
  194. }
  195. return 0;
  196. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty