27 lines
490 B
C++
27 lines
490 B
C++
#pragma once
|
|
|
|
template <class T>
|
|
struct List {
|
|
struct Container {
|
|
T* t;
|
|
Container* next;
|
|
Container(T* t) : t(t) {}
|
|
};
|
|
|
|
Container* first;
|
|
Container* last;
|
|
|
|
void add(T* t) {
|
|
Container* c = new Container{t};
|
|
first == nullptr ? first = c : last->next = c;
|
|
last = c;
|
|
}
|
|
|
|
static void exec(List list, void(*f)(T*)) {
|
|
for (List::Container *c = list.first; c; c = c->next) {
|
|
f(c->t);
|
|
}
|
|
}
|
|
|
|
};
|