Find the Middle Node in a Singly Linked List

Given a singly linked list, this function returns the middle node of the list. If the list has an even number of nodes, the function returns the node at the start of the second half of the list.

Problem

```Given a singly linked list, write a function that returns the middle node of the list. If the list has an even number of nodes, the function should return the node at the start of the second half of the list.
Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6
Output: 4```

Solution

This solution is in C++. Our A.I. can create solutions in multiple languages.
by kayakane
```#include <iostream>
#include <vector>

using namespace std;

struct Node {
int data;
Node* next;
};

Node* createNode(int data) {
Node* node = new Node;
node->data = data;
node->next = NULL;
return node;
}

Node* createList(vector<int> data) {
for (int i = 1; i < data.size(); i++) {
current->next = createNode(data[i]);
current = current->next;
}
}

while (current != NULL) {
cout << current->data << " ";
current = current->next;
}
cout << endl;
}

Node* fast = head; while (fast != NULL && fast->next != NULL) {
slow = slow->next;
fast = fast->next->next;
}
return slow;
}

int main() {
vector<int> data = {1, 2, 3, 4, 5, 6};