Type like pro

# Binary tree to linked list

## Problem

Given a binary tree create individual linked lists from each level of the binary tree.

## Solution

We will do the level order traversal of the binary tree with a marker node to tell us when a level ends. While doing so we will keep the node values added to the linked lists. After each level we will add the linked list to the result and crate a new one for the next level.

## Code

```import java.util.ArrayList;
import java.util.List;

{

public static void main(String[] args)
{
BinaryTreeNode a=new BinaryTreeNode(1);
BinaryTreeNode b=new BinaryTreeNode(2);
BinaryTreeNode c=new BinaryTreeNode(3);
BinaryTreeNode d=new BinaryTreeNode(4);
BinaryTreeNode e=new BinaryTreeNode(5);
BinaryTreeNode f=new BinaryTreeNode(6);
BinaryTreeNode g=new BinaryTreeNode(7);
BinaryTreeNode h=new BinaryTreeNode(8);
BinaryTreeNode i=new BinaryTreeNode(9);
a.left=b;
a.right=c;
b.right=d;
c.left=e;
c.right=f;
d.left=g;
d.right=h;
g.right=i;

}

BinaryTreeNode root)
{
if(root==null)
return result;
BinaryTreeNode marker=new BinaryTreeNode(-1);
while(!queue.isEmpty())
{
BinaryTreeNode btNode=queue.poll();
if(btNode==marker)
{

if(!queue.isEmpty())
{
}
continue;
}
{
}
else
{
prev=prev.next;
}
if(btNode.left!=null)
if(btNode.right!=null)

}
return result;
}
static class BinaryTreeNode
{
public BinaryTreeNode left;
public BinaryTreeNode right;
public int value;
public BinaryTreeNode(int value)
{
this.value=value;
}
}

{
public int value;
{
this.value=value;
}
}