⎗ ✓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60template<class T> struct list { struct node { T value; node* next; node* prev; }; node* head = nullptr; explicit list(int n) { head = reinterpret_cast<node *>(calloc(1, sizeof(node))); node* prev = head; for (int i = 0 + 1; i < n; ++i) { node* cur = reinterpret_cast<node *>(calloc(1, sizeof(node))); cur->prev = prev; cur->prev->next = cur; cur->value = i; prev = cur; cur = cur->next; } } void reverse() { node* next = nullptr; for (node* cur = head; cur; cur = next) { next = cur->next; cur->next = cur->prev; cur->prev = next; head = cur; } } void dump(ostream& os) const { for (node* i = head; i; i = i->next) os << i->value << " "; } ~list() { node* next = nullptr; for(node* iter = head; iter; iter = next) { next = iter->next; free(iter); } head = nullptr; } }; int main() { using List = list<int>; List l(10); l.reverse(); l.dump(cout); }