7 questions. Covers Reverse in groups of k.
Questions 1 to 5 of 7
print_reverse
4 3 2 1
length_rec
length_loop
cpp #include <iostream> struct Node { int value; Node* next; }; void walk(const Node* head) { if (head == nullptr) { std::cout << "end\n"; return; } std::cout << "down " << head->value << '\n'; walk(head->next); std::cout << "up " << head->value << '\n'; } int main() { Node c{3, nullptr}, b{2, &c}, a{1, &b}; walk(&a); }
cpp #include <iostream> struct Node { int value; Node* next; }; Node* bad_reverse(Node* head) { if (head == nullptr || head->next == nullptr) { return head; } bad_reverse(head->next); head->next->next = head; head->next = nullptr; return head; } int main() { Node c{3, nullptr}, b{2, &c}, a{1, &b}; Node* result = bad_reverse(&a); std::cout << result->value << '\n'; }
5 question(s) left on this page.