<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>qnighy</author_name>
  <author_url>https://blog.hatena.ne.jp/qnighy/</author_url>
  <blog_title>簡潔なQ</blog_title>
  <blog_url>https://qnighy.hatenablog.com/</blog_url>
  <categories>
    <anon>Rust</anon>
  </categories>
  <description>概要: 生存期間の関係で、ループでは書けないが末尾再帰では書けるアルゴリズムの例を挙げる。 単方向リンクリスト 次のような単純なリンクリストを考える。 struct List&lt;T&gt; { root: Option&lt;Box&lt;Node&lt;T&gt;&gt;&gt;, } struct Node&lt;T&gt; { value: T, next: Option&lt;Box&lt;Node&lt;T&gt;&gt;&gt;, } backの実装 単方向リンクリストの末尾要素の取得は O(n) である。これは次のように書くことができる。 impl&lt;T&gt; List&lt;T&gt; { fn back(&amp;self) -&gt; Option&lt;&amp;T&gt; { let mut node = if…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fqnighy.hatenablog.com%2Fentry%2F2017%2F05%2F06%2F070000&quot; title=&quot;末尾再帰をループにできないRustプログラムの例 - 簡潔なQ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/q/qnighy/20170505/20170505221029.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2017-05-06 07:00:00</published>
  <title>末尾再帰をループにできないRustプログラムの例</title>
  <type>rich</type>
  <url>https://qnighy.hatenablog.com/entry/2017/05/06/070000</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
