-
-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance the code of TreeTraversal and EuclideanAlgorithm for C# #120
Enhance the code of TreeTraversal and EuclideanAlgorithm for C# #120
Conversation
…ersal. Fix incorrect ConsoleWriteLine. Use local functions. Create constructor for Node, which takes an id. Remove unnecessary curly braces. Remove redundant CreateTree method and just put the code into the constructor. Remove unnecessary comment. Remove the now redundant TreeTraversalMdAdditional. Sort the methods so that they have the same order as in the text.
…with CRLF line terminators".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very few things I can say about C# code, but I tried my best.
tree.DFSRecursivePostorder(); | ||
|
||
// Console.WriteLine("DFSRecursiveInorder (fail)"); | ||
// tree.DFSRecursiveInorderBinary(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these left over from a debugging session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People can uncomment that, to see, that the algorithm will throw an exception then (because the node has more than 2 children). After that a new Tree is created with only 2 children per node and the method can be used without problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case: What about a comment above these 2 lines that explains what you just explained here? Just something like // Uncomment these to see what happens if ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Console.WriteLine(node.Id); | ||
|
||
foreach (var c in node.Children) | ||
DFSRecursive(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a C# expert, but I'm pretty sure that omitting brackets for loops and conditions is dangerous no matter which language you're using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gustorn What do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be dangerous, sure, but C#'s bracket style kinda encourages it. Having a single-line statement stretch into 3 eats up a lot of vertical space. I don't really mind either way but as long as it's a short, single line I think omitting the parens is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shall allow it, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you put the comments in multiple lines
As a note, I think putting the comments in multiple lines looks a little cleaner, but the lines will soft-wrap in the actual book. |
I'm not a fan of soft-wrapping, but I have to agree that it will look even worse when you hard-wrap the lines and then the soft-wrapping in the gitbook kicks in, so I don't mind in this case. |
I think it's good. I hope I didn't miss anything. |
I'll open a new PR applying the restructuring suggested by @Gustorn in #137 |
Enhance and refactor the code of TreeTraversal.
Move all additional methods from TreeTraversalMdAdditional to TreeTraversal and delete the leftover files.
Delete EuclideanAlgorithmMdAdditional as well.