diff --git a/main.cpp b/main.cpp index b26f302..17a8b68 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +using namespace std; class Node { public: @@ -37,6 +38,25 @@ class SinglyLinkedList { void reverseLinkedList() { // TODO: Students will implement this function + Node* temp = head; + int node_count = 0; + while (temp != nullptr) { + node_count++; + temp = temp->next; + } + temp = head; + int *datatot = new int[node_count]; + for (int i = 0; i < node_count; i++) { + datatot[i] = temp->data; + Node* old_node = temp; + temp = temp->next; + delete[] old_node; + } + head = nullptr; + for (int i = node_count - 1; i >= 0; i--) { + append(datatot[i]); + } + delete[] datatot; std::cout << "Implement reverseLinkedList()" << std::endl; } };