view graphs_trees/link_tree_levels/question.rst @ 0:20fea762903e

Import some exercises and solutions
author Louis Opter <kalessin@kalessin.fr>
date Sat, 29 Jun 2013 19:30:31 -0700
parents
children
line wrap: on
line source

Link Node at the Same Height in a Binary Tree
=============================================

Given a binary tree, turn each level of the tree into a linked list from left
to right. The binary tree node already have a field for the reference/pointer
to build the list.

::

                 1 -> NULL
          2      ->      4 -> NULL
     5   ->   6   ->   7 -> 8 -> NULL
   9      ->    10    ->      11 -> NULL


.. code-block:: python

   class Node:
     left = None
     right = None
     sibling = None