Conversation
mamo3gr
reviewed
Jan 1, 2026
Comment on lines
+19
to
+22
| forward = node.next | ||
| node.next = previous | ||
| previous = node | ||
| node = forward |
There was a problem hiding this comment.
ここの複雑なお手玉をいかに分かりやすく書くかが腕の見せどころだと思います。(私もはじめは使っていたのですが)forward や previous は文脈を読み手と共有できていないと、何の次・前なのか伝わりません。
forward は次に処理するノードへの参照の退避先なので、saved_next とか next_node の方が分かりやすいかもしれません。
previous はすでに反転済みの最後なので last_reversed とかどうでしょうか。
また、処理単位ごとに空行で分けるとなおわかりよいかもしれません。
Suggested change
| forward = node.next | |
| node.next = previous | |
| previous = node | |
| node = forward | |
| # 次のループに渡す参照の退避 | |
| forward = node.next | |
| # 入れ替え処理 | |
| node.next = previous | |
| # 次のループへの引き継ぎ | |
| previous = node | |
| node = forward |
|
コメント集にもありますが他の解法として再帰をつかったやり方もありますね
|
oda
reviewed
Jan 3, 2026
| - https://github.com/tNita/arai60/pull/8/files | ||
| - `スタックとして使うのであれば list で十分だと思います。一般に、同じ目的に使えるデータ構造が複数ある場合、その中で一番実装が軽いものを選ぶことが多いように思います。` | ||
| - dequeをstackとして使う人がいるなとは思っていたが、どっちでもいいなら書く量が少ない普通のlist派だった | ||
| - deque派の意見が聞きたいところ |
There was a problem hiding this comment.
どちらでもいいと思います。List はリアロケーションで遅くなるときがあるので、それが本当に問題になるような場合には deque というくらいですかね。
| - 最初から処理する方の再帰と再帰でcallStackに積んで(言葉があっているかは怪しい)積み終わったのちに順々に処理しているように見える | ||
| - `関数は基本的に中を読みたくないのです。`なので関数名が長く説明的でも良いみたい | ||
| - headがNoneの時は一番最初にNoneを返した方が最後で場合分けするより実装時に考慮事項が減り楽出し、読んでる時にもListNodeが入っている前提で読めるのでわかりやすい | ||
| - 頭がこんがらがっているので問題をお気に入りしておき再帰はまた今後やる |
There was a problem hiding this comment.
再帰関数は、関数自体はマニュアルだと思って、大量の部下にそのマニュアルをバラマキ、部下同士が仕事を依頼し合うと考えるとできませんかね。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
解く問題
Reverse Linked List
次に解く問題
Kth Largest Element In A Stream