#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
struct List {
public:
List();
~List();
struct Map {
string get(int param);
string arriv;
string flightID;
string inits;
string depatDate;
Map(string arriv, string flightID, string inits, string depatDate) {
this->arriv = arriv;
this->flightID = flightID;
this->inits = inits;
this->depatDate = depatDate;
}
};
void push_back(Map* data);
int getSize();
Map* operator[](const int index);
void removeElem(const char mode = 's');
void clear();
struct Node {
Map* data;
Node* next;
Node(Map* data, Node* next = NULL) {
this->data = data;
this->next = next;
}
};
int size;
Node* head;
};
List::List() {
size = 0;
head = NULL;
}
void List::push_back(Map* data) {
if (this->head == NULL) {
this->head = new Node(data);
}
else {
Node* current = this->head;
while (current->next != NULL) {
current = current->next;
}
current->next = new Node(data);
}
size++;
}
int List::getSize() {
return size;
}
List::Map* List::operator[](const int index) {
Node* current = this->head;
int counter = 0;
while (current->next != NULL) {
if (counter == index) {
return current->data;
}
counter++;
current = current->next;
}
}
void List::removeElem(const char mode) {
if (mode == 's') {
Node* temp = this->head;
head = head->next;
delete temp;
size--;
}
if (mode == 'e') {
Node* current = this->head;
while (current->next != NULL) {
current = current->next;
}
delete current;
size--;
}
}
void List::clear() {
removeElem('s');
}
List::~List() {
clear();
}
string List::Map::get(int param) {
switch (param)
{
case 0: return arriv;
case 1: return flightID;
case 2: return inits;
case 3: return depatDate;
}
}
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
List list;
List::Map* request = new List::Map(
"023",
"Spain",
"Emelyanov R.A",
"10.09.2023"
);
list.push_back(request);
List::Map* request1 = new List::Map(
"024",
"Spain",
"Emelyanov R.A",
"20.09.2023"
);
list.push_back(request1);
List::Map* request2 = new List::Map(
"025",
"japan",
"Emelyanov R.A",
"30.09.2023"
);
list.push_back(request2);
cout << list.getSize() << endl;
cout << list[0]->get(0) << endl;
return 0;
}
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
List list;
List::Map* request = new List::Map(
"023",
"Spain",
"Em R.A",
"10.09.2023"
);
list.push_back(request);
List::Map* request1 = new List::Map(
"024",
"Spain",
"Em R.A",
"20.09.2023"
);
list.push_back(request1);
List::Map* request2 = new List::Map(
"025",
"japan",
"Em R.A",
"30.09.2023"
);
list.push_back(request2);
cout << list.getSize() << endl;
cout << list[0]->get(0) << endl;
return 0;
}