#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
using namespace std;
struct city
{
string name_f;
string name_p;
string date;
string genre;
struct city *next;
struct city *previous;
};
city *head=NULL;
city *last=NULL;
city *current=NULL; //текущий элемент
city *temp=NULL;
city *newList=NULL ;
/* Процедура создания добавления в список */
void add_name(string namef_,string namep_, string date_, string genre_)
{
if(head!=NULL)
{
newList=new city;
newList->name_f=namef_;
newList->name_p=namep_;
newList->date=date_;
newList->genre=genre_;
newList->next=NULL;
newList->previous=current;
current->next=newList;
last=newList;
current=newList;
}
else
{
newList=new city;
newList->name_f=namef_;
newList->name_p=namep_;
newList->date=date_;
newList->genre=genre_;
head=newList;
newList->next=NULL;
newList->previous=NULL;
current=newList;
last=head;//Забыли установить!!!
}
}
/* Процедура удаления узла */
void delete_unit()
{ newList=head;
if(newList == head->next)
{
delete head; //удаление элемента
head=NULL;
}
else
{
head=head->next;
head->previous=NULL;
delete newList;
}
}
/* Процедура вывода списка слева направо */
int count_L()
{
int count;
newList = head;
if(newList == NULL)
{
count = 0;
}
else
{
while(newList != NULL)
{
count=count+1;
newList = newList->next;
}
}
return count;
}
void show_list(void)
{
struct city *info;
info = head;
while(info)
{
cout<<info->name_f<<"\t";
cout<<info->name_p<<"\t";
cout<<info->date<<"\t";
cout<<info->genre<<"\t";
cout<<"\n";
info = info->next;
}
}
/* Процедура вывода списка справа налево */
void show_list_1(void)
{
struct city *info;
info = last;
while(info)
{
cout<<info->name_f<<"\t";
cout<<info->name_p<<"\t";
cout<<info->date<<"\t";
cout<<info->genre<<"\t";
cout<<"\n";
info = info->previous;
}
}
/* Тело основной программы */
int main(void)
{
setlocale(LC_ALL,"Russian");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
string name_f;
string name_p;
string date;
string genre;
int key=-1;
while(key)
{
cout<<"1. Enter name\n";
cout<<"2. Delete name\n";
cout<<"3. Show names\n";
cout<<"4. Show names from end\n";
cout<<"0. Exit\n";
cin>>key;
switch (key)
{
case 1:
{
cout<<"Введите название театра\n";
cin>>name_f;
cout<<"Ведите название представления\n";
cin>>name_p;
cout<<"Ведите дату представления\n";
cin>>date;
cout<<"Ведите жанр представления\n";
cin>>genre;
add_name(name_f,name_p,date,genre);
break;
}
case 2:
{
int n = count_L();
if(n == 0)
{
cout<<"Невозможноу удалить элементы в стеке 0 элементов";
}
else if (n == 1)
{
cout<<"Невозможноу удалить элементы в стеке 1 элемент";
}
else if (n > 2)
{
delete_unit();
delete_unit();
}
break;
}
case 3:
{
cout<<"Список с лева на право\n";
show_list();
break;
}
case 4:
{
cout<<"Список с права на лево\n";
show_list_1();
break;
}
case 0:
{
cout<<"Пока\n";
getch();
break;
}
default:
{
cout<<"Error\n";
getch();
break;
}
if (key==0) break;
}
}
return 0;
}