diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/SinglyLinkedListWarmUp.iml b/.idea/SinglyLinkedListWarmUp.iml new file mode 100644 index 0000000..4c94235 --- /dev/null +++ b/.idea/SinglyLinkedListWarmUp.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..1f0ef49 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,580 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..077e3e0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.cpp b/main.cpp index b26f302..a4edfcf 100644 --- a/main.cpp +++ b/main.cpp @@ -37,7 +37,21 @@ class SinglyLinkedList { void reverseLinkedList() { // TODO: Students will implement this function + std::cout << "Implement reverseLinkedList()" << std::endl; + + Node* prev = nullptr; + Node* curr = head; + Node* next = nullptr; + + while (curr) { + next = curr->next; // Store next node + curr->next = prev; // Reverse current node’s pointer + prev = curr; // Move prev to current + curr = next; // Move current to next + } + + head = prev; // Update head to new front } }; @@ -48,6 +62,7 @@ int main() { list.append(3); list.printList(); + // Student should implement reverseLinkedList() list.reverseLinkedList(); list.printList(); diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..1889197 Binary files /dev/null and b/main.exe differ