Make middle node head in a linked list
Move middle node of linked list to front position, But first we are need to find the middle node.
Suppose we are inserted the following (1,2,3,4,5,6,7) node in a sequence.
We can solve this problem in a two ways.
Method 1: This is simplest method first count all linked list nodes from linked list traversal. after that iterates ((count1)/2) nodes of tree and move middle node to first position. This process time complexity is O(n).

1) Make middle node as head of linked list using node counting in java
2) Make middle node as head of linked list using node counting in c++
3) Make middle node as head of linked list using node counting in c
4) Make middle node as head of linked list using node counting in php
5) Make middle node as head of linked list using node counting in golang
6) Make middle node as head of linked list using node counting in kotlin
7) Make middle node as head of linked list using node counting in swift
8) Make middle node as head of linked list using node counting in scala
9) Make middle node as head of linked list using node counting in python
10) Make middle node as head of linked list using node counting in ruby
11) Make middle node as head of linked list using node counting in c#
12) Make middle node as head of linked list using node counting in vb.net
13) Make middle node as head of linked list using node counting in node js
14) Make middle node as head of linked list using node counting in TypeScript
Method 2: In this methode are use two pointer variable that are hold the reference of first node of linked list.
first point are visiting one by one into next upcoming nodes, and second pointer are visiting every second node. Continue this process until second pointer is not NULL or that is not possible to visit that is next upcoming nodes. first pointer are hold the reference of middle pointer and we can split this node of linked list and add this node at first position
Here given code implementation process.

1) Make the middle node head in a linked list in java
2) Make the middle node head in a linked list in c#
3) Make the middle node head in a linked list in c++
4) Make the middle node head in a linked list in c
5) Make the middle node head in a linked list in golang
6) Make the middle node head in a linked list in kotlin
7) Make the middle node head in a linked list in swift
8) Make the middle node head in a linked list in scala
9) Make the middle node head in a linked list in ruby
10) Make the middle node head in a linked list in python
11) Make the middle node head in a linked list in TypeScript
12) Make the middle node head in a linked list in node js
13) Make the middle node head in a linked list in php
14) Make the middle node head in a linked list in vb.net
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment