Мне нужно сделать односвязный список, данными которого являются что-то наподобие словарей, не суть. Вроде работает, но данные из последнего элемента списка оказываются пустыми. Помогите, пожалуйста!
struct 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);
Map* operator[](const int index);
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++;
}
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;
}
}