<commit_before>---
layout: problem
title: "Tree To Reversed List"
type: Challenge
tags: [recursion, tree recursion]
categories: [cs61a, sp13, problems]
author_name: <NAME>
author_url: http://markmiyashita.com
google_plus: 101180624276428786239

published: true
solution: true
---
<p>
  This problem uses the <a href="http://markmiyashita.com/cs61a/code/tree_recursion/tree.py">Tree class</a> and the template for this file can be downloaded <a href="http://markmiyashita.com/cs61a/code/tree_recursion/tree_to_reversed_list.py">here.</a>
</p>

<p>
  In this problem, the input is a binary tree and the output is a list. The list is formed by getting the rightmost entry first. If you haven't already, the traversal questions located <a href="http://markmiyashita.com/cs61a/sp13/problems/trees_trees_everywhere/">here</a> may help you.
</p>

<pre>
  <code class="prettyprint">
def tree_to_reversed_list(tree):
    """
    >>> t = Tree(5, Tree(1, None, Tree(4)), Tree(7, Tree(6), Tree(8)))
    >>> tree_to_reversed_list(t)
    [8, 7, 6, 5, 4, 1]
    """
    "***YOUR CODE HERE***"
  </code>
</pre>

{% if page.solution %}
<button onclick="toggleSolution()">Toggle Solution</button>

<div class="solution">
  <pre>
    <code class="prettyprint">
def tree_to_reversed_list(tree):
    """
    >>> t = Tree(5, Tree(1, None, Tree(4)), Tree(7, Tree(6), Tree(8)))
    >>> tree_to_reversed_list(t)
    [8, 7, 6, 5, 4, 1]
    """
    lst = []
    if tree.right:
        lst.extend(tree_to_reversed_list(tree.right))
    lst.append(tree.entry)
    if tree.left:
        lst.extend(tree_to_reversed_list(tree.left))
    return lst
    </code>
  </pre>
  
  <p>
    
  </p>
</div>
{% endif %}<commit_msg>updated solutions<commit_after>---
layout: problem
title: "Tree To Reversed List"
type: Challenge
tags: [recursion, tree recursion]
categories: [cs61a, sp13, problems]
author_name: <NAME>
author_url: http://markmiyashita.com
google_plus: 101180624276428786239

published: true
solution: true
---
<p>
  This problem uses the <a href="http://markmiyashita.com/cs61a/code/tree_recursion/tree.py">Tree class</a> and the template for this file can be downloaded <a href="http://markmiyashita.com/cs61a/code/tree_recursion/tree_to_reversed_list.py">here.</a>
</p>

<p>
  In this problem, the input is a binary tree and the output is a list. The list is formed by getting the rightmost entry first. If you haven't already, the traversal questions located <a href="http://markmiyashita.com/cs61a/sp13/problems/trees_trees_everywhere/">here</a> may help you.
</p>

<pre>
  <code class="prettyprint">
def tree_to_reversed_list(tree):
    """
    >>> t = Tree(5, Tree(1, None, Tree(4)), Tree(7, Tree(6), Tree(8)))
    >>> tree_to_reversed_list(t)
    [8, 7, 6, 5, 4, 1]
    """
    "***YOUR CODE HERE***"
  </code>
</pre>

{% if page.solution %}
<button onclick="toggleSolution()">Toggle Solution</button>

<div class="solution">
  <pre>
    <code class="prettyprint">
def tree_to_reversed_list(tree):
    """
    >>> t = Tree(5, Tree(1, None, Tree(4)), Tree(7, Tree(6), Tree(8)))
    >>> tree_to_reversed_list(t)
    [8, 7, 6, 5, 4, 1]
    """
    lst = []
    if tree is not None:
        if tree.right:
            lst.extend(tree_to_reversed_list(tree.right))
        lst.append(tree.entry)
        if tree.left:
            lst.extend(tree_to_reversed_list(tree.left))
    return lst
    </code>
  </pre>
  
  <p>
    
  </p>
</div>
{% endif %}
{'fraction_non_alphanumeric': 0.16194922672891743, 'fraction_numerical': 0.0332652465713452, 'mean_word_length': 3.7282758620689656, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5933227', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1253, 'n_words': 318}