T data;
Node* next;
};
private:
Node* head, * tail;
unsigned long length = 0;
public:
List() {
head = NULL;
tail = NULL;
}
void append(const T& data) {
Node* temp = new Node;
temp->data = data;
temp->next = NULL;
length += 1;
if (head == NULL) {
head = temp; tail = temp; temp = NULL;
}
else {
tail->next = temp;
tail = temp;
}
}
const T get(int e = 0) {
Node* temp = head;
unsigned long counter = 0;
T data = NULL;
if (e <= length)
//return ? ;
while (counter <= e) {
counter += 1;
data = temp->data;
temp = temp->next;
}
return data;
}
unsigned long size() {
return length;
}
};
Оберните код в теги: 3 символа ` до и после кода (в случае одиночной конструкции достаточно 1 ` с обеих сторон). Спасибо!
Мне в основном интересно, почему вы пишете const T в возвращаемом значении
можно ещё обсудить, нужен ли в принципе листу доступ по индексу. В стандартной библиотеке такого нет, например
Обсуждают сегодня