#include <iostream>
using namespace std;
class List
{
public:
List();
class Node {
public:
Node* pNext;
int data;
Node(int data, Node* pNext = nullptr) {
this->data = data;
this->pNext = pNext;
}
};
int Size;
Node *Top;
void push_back(int data);
void lout(List&lst);
void lin(List &lst);
void firstTask(List& lst1, List& lst2);
};
List::List() {
Size = 0;
Top = nullptr;
}
void List::push_back(int data) {
if (Top == nullptr) {
Top = new Node(data);
}
else {
Node* current = this->Top;
while (current->pNext != nullptr) {
current = current->pNext;
}
current->pNext = new Node(data);
}
Size++;
}
void List::lout(List&lst) {
cout << "Your list:" << endl;
Node* current = Top;
for (int i=0;i<Size;i++) {
cout << current->data << " ";
current = current->pNext;
}
cout << endl;
}
void List::lin(List&lst) {
cout << "How many time you want to fill in elements of list? Do not enter not integer data type!" << endl;
int answer;
cin >> answer;
for (int i = 0; i < answer; i++) {
int input;
cin >> input;
lst.push_back(input);
}
}
void List::firstTask(List&lst1,List&lst2) {
List tmp;
}
int main() {
List lst1;
lst1.lin(lst1);
lst1.lout(lst1);
List lst2;
lst2.lin(lst2);
lst2.lout(lst2);
lst2.firstTask(lst1,lst2);
}
Как мне сделать так, чтобы Тор в методе firstTask указывал на крайний элемент списка, а не на первый?