# How to split a circular linked list into two halves?

You need to divide a circular linked list with divisions of the same size. If the circular linked list is odd, you must change the number of nodes. It is an even number. Explain with pictures. See the picture below.

### Algorithm:

1. First count the number of nodes in the Circular Link List // The way to divide the list is the Floyd algorithm, which is much better.
2. Next, you need to match the list.
3. Third, I cut the list in half. The front is the same size as the rear. Finally, we need to create two circular linked lists.
```struct node
{
int data;
struct node *next;
};
struct node * fastNode = head;
struct node * slowNode = head;

return;
while (fastNode -> next != head && fastNode -> next -> next != head) {
fastNode = fastNode -> next -> next;
slowNode = slowNode -> next;
}
if (fastNode -> next -> next == head)
fastNode = fastNode -> next;
fastNode -> next = slowNode -> next;
}```

#### Here Code:

```#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
{
return;
{
fast_ptr = fast_ptr->next->next;
slow_ptr = slow_ptr->next;
}
fast_ptr = fast_ptr->next;
fast_ptr->next = slow_ptr->next;
}
{
Node *ptr1 = new Node();
ptr1->data = data;
{
temp = temp->next;
temp->next = ptr1;
}
else
ptr1->next = ptr1;
}
{
{
cout << endl;
do {
cout << temp->data << " ";
temp = temp->next;
}
}
int main()
{
int list_size, i;
cout << "Original Circular Linked List";
cout << "\nFirst Circular Linked List";
cout << "\nSecond Circular Linked List";
return 0;
}```

### Recommended Articles:

#### References:

Help Me Please: If you found any error in the content or example please let us know by comment also write your suggestion or if any doubt in the concept please feel free to write us in the comment section.

## Practice your Code online here

(Visited 134 times, 1 visits today)

Article Rating
Subscribe
Notify of
Inline Feedbacks

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]

[…] How to split a circular linked list into two halves? […]