|
69 | 69 |
|
70 | 70 |
|
71 | 71 |
|
| 72 | + <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css"> |
| 73 | + |
| 74 | + |
| 75 | + |
72 | 76 | <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
|
73 | 77 |
|
74 | 78 |
|
@@ -3711,44 +3715,44 @@ <h2 id="二、解题思路"><a name="二0
|
3711 | 3715 | <p>使用栈的方式进行。</p>
|
3712 | 3716 | <p>将链表从头到尾压入栈内,出栈的过程就对应着从尾到头。</p>
|
3713 | 3717 | <h3 id="三、解题代码"><a name="三、解题代码" class="anchor-navigation-ex-anchor" href="#三、解题代码"><i class="fa fa-link" aria-hidden="true"></i></a>三、解题代码</h3>
|
3714 |
| -<pre><code class="lang-java">public class Test { |
3715 |
| - /** |
| 3718 | +<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>{ |
| 3719 | + <span class="hljs-comment">/** |
3716 | 3720 | * 结点对象
|
3717 |
| - */ |
3718 |
| - public static class ListNode { |
3719 |
| - int val; // 结点的值 |
3720 |
| - ListNode nxt; // 下一个结点 |
| 3721 | + */</span> |
| 3722 | + <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ListNode</span> </span>{ |
| 3723 | + <span class="hljs-keyword">int</span> val; <span class="hljs-comment">// 结点的值 </span> |
| 3724 | + ListNode nxt; <span class="hljs-comment">// 下一个结点 </span> |
3721 | 3725 | }
|
3722 | 3726 |
|
3723 |
| - /** |
| 3727 | + <span class="hljs-comment">/** |
3724 | 3728 | * 输入个链表的头结点,从尾到头反过来打印出每个结点的值
|
3725 | 3729 | * 使用栈的方式进行
|
3726 | 3730 | *
|
3727 |
| - * @param root 链表头结点 |
3728 |
| - */ |
3729 |
| - public static void printListInverselyUsingIteration(ListNode root) { |
3730 |
| - Stack<ListNode> stack = new Stack<>(); |
3731 |
| - while (root != null) { |
| 3731 | + * <span class="hljs-doctag">@param</span> root 链表头结点 |
| 3732 | + */</span> |
| 3733 | + <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">printListInverselyUsingIteration</span><span class="hljs-params">(ListNode root)</span> </span>{ |
| 3734 | + Stack<ListNode> stack = <span class="hljs-keyword">new</span> Stack<>(); |
| 3735 | + <span class="hljs-keyword">while</span> (root != <span class="hljs-keyword">null</span>) { |
3732 | 3736 | stack.push(root);
|
3733 | 3737 | root = root.nxt;
|
3734 | 3738 | }
|
3735 | 3739 | ListNode tmp;
|
3736 |
| - while (!stack.isEmpty()) { |
| 3740 | + <span class="hljs-keyword">while</span> (!stack.isEmpty()) { |
3737 | 3741 | tmp = stack.pop();
|
3738 |
| - System.out.print(tmp.val + " "); |
| 3742 | + System.out.print(tmp.val + <span class="hljs-string">" "</span>); |
3739 | 3743 | }
|
3740 | 3744 | }
|
3741 | 3745 |
|
3742 |
| - /** |
| 3746 | + <span class="hljs-comment">/** |
3743 | 3747 | * 输入个链表的头结点,从尾到头反过来打印出每个结点的值
|
3744 | 3748 | * 使用递归的方式进行
|
3745 | 3749 | *
|
3746 |
| - * @param root 链表头结点 |
3747 |
| - */ |
3748 |
| - public static void printListInverselyUsingRecursion(ListNode root) { |
3749 |
| - if (root != null) { |
| 3750 | + * <span class="hljs-doctag">@param</span> root 链表头结点 |
| 3751 | + */</span> |
| 3752 | + <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">printListInverselyUsingRecursion</span><span class="hljs-params">(ListNode root)</span> </span>{ |
| 3753 | + <span class="hljs-keyword">if</span> (root != <span class="hljs-keyword">null</span>) { |
3750 | 3754 | printListInverselyUsingRecursion(root.nxt);
|
3751 |
| - System.out.print(root.val + " "); |
| 3755 | + System.out.print(root.val + <span class="hljs-string">" "</span>); |
3752 | 3756 | }
|
3753 | 3757 | }
|
3754 | 3758 | }
|
@@ -3798,7 +3802,7 @@ <h1 class="search-results-title">No results matching "<span class='search-query'
|
3798 | 3802 | <script>
|
3799 | 3803 | var gitbook = gitbook || [];
|
3800 | 3804 | gitbook.push(function() {
|
3801 |
| - gitbook.page.hasChanged({"page":{"title":"03.从尾到头打印链表","level":"5.1.3","depth":2,"next":{"title":"04.重建二叉树","level":"5.1.4","depth":2,"path":"algorithm/For-offer/04.md","ref":"algorithm/For-offer/04.md","articles":[]},"previous":{"title":"02.替换空格","level":"5.1.2","depth":2,"path":"algorithm/For-offer/02.md","ref":"algorithm/For-offer/02.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-highlight","-livereload","search-plus@^0.0.11","simple-page-toc@^0.1.1","github@^2.0.0","github-buttons@2.1.0","edit-link@^2.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","ace@^0.3.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","sectionx@^3.1.0","local-video@^1.0.1","anchor-navigation-ex@0.1.8","favicon@^0.0.2"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © ruheng.com 2017","modify_label":"该文件修订时间:","modify_format":"YYYY-MM-DD HH:mm:ss"},"emphasize":{},"ace":{},"github":{"url":"https://github.com/LRH1993/android_interview"},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"splitter":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"anchor-navigation-ex":{"isRewritePageTitle":false,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"github-buttons":{"repo":"LRH1993/android_interview","types":["star"],"size":"small"},"expandable-chapters-small":{},"local-video":{},"advanced-emoji":{"embedEmojis":false},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/LRH1993/android_interview/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"search-plus":{}},"theme":"default","author":"ruheng","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Android校招面试指南","language":"zh-hans","output.name":"site","links":{"sidebar":{"Home":"http://lruheng.com/"}},"gitbook":"3.2.3","description":"Android面试必备,记录自己的秋招之路"},"file":{"path":"algorithm/For-offer/03.md","mtime":"2017-08-22T07:53:58.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-16T12:05:21.906Z"},"basePath":"../..","book":{"language":""}}); |
| 3805 | + gitbook.page.hasChanged({"page":{"title":"03.从尾到头打印链表","level":"5.1.3","depth":2,"next":{"title":"04.重建二叉树","level":"5.1.4","depth":2,"path":"algorithm/For-offer/04.md","ref":"algorithm/For-offer/04.md","articles":[]},"previous":{"title":"02.替换空格","level":"5.1.2","depth":2,"path":"algorithm/For-offer/02.md","ref":"algorithm/For-offer/02.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-livereload","search-plus@^0.0.11","simple-page-toc@^0.1.1","github@^2.0.0","github-buttons@2.1.0","edit-link@^2.0.2","advanced-emoji@^0.2.1","anchors@^0.7.1","include-codeblock@^3.0.2","ace@^0.3.2","emphasize@^1.1.0","katex@^1.1.3","splitter@^0.0.8","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","sectionx@^3.1.0","local-video@^1.0.1","anchor-navigation-ex@0.1.8","favicon@^0.0.2"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © ruheng.com 2017","modify_label":"该文件修订时间:","modify_format":"YYYY-MM-DD HH:mm:ss"},"emphasize":{},"ace":{},"github":{"url":"https://github.com/LRH1993/android_interview"},"simple-page-toc":{"maxDepth":3,"skipFirstH1":true},"splitter":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"highlight":{},"anchor-navigation-ex":{"isRewritePageTitle":false,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"github-buttons":{"repo":"LRH1993/android_interview","types":["star"],"size":"small"},"expandable-chapters-small":{},"local-video":{},"advanced-emoji":{"embedEmojis":false},"include-codeblock":{"check":false,"edit":false,"fixlang":false,"lang":"","template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/LRH1993/android_interview/edit/master"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"search-plus":{}},"theme":"default","author":"ruheng","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Android校招面试指南","language":"zh-hans","output.name":"site","links":{"sidebar":{"Home":"http://lruheng.com/"}},"gitbook":"3.2.3","description":"Android面试必备,记录自己的秋招之路"},"file":{"path":"algorithm/For-offer/03.md","mtime":"2017-08-22T07:53:58.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-16T13:00:43.989Z"},"basePath":"../..","book":{"language":""}}); |
3802 | 3806 | });
|
3803 | 3807 | </script>
|
3804 | 3808 | </div>
|
|
0 commit comments