-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add Inorder Traversal in Kotlin #2657
Conversation
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.
Please fix PR template, fill bullets or remove unnecessary ones. Also the issue number has to go like Fixes#someNumber
fun main() //Main function | ||
{ | ||
BinaryTree tree = new BinaryTree(); | ||
tree.root = new Node(10); |
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.
Please take Dynamic inputs instead of hard coded ones.
printInorder(node.right); | ||
} | ||
|
||
fun printInorder():void |
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.
please remove unnecessary space here.
root = null; | ||
} | ||
|
||
fun printInorder(Node: node):void //function to print inorder traversal |
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.
Please remove the comments from the sides and add on a separate line before the function.
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.
Overall the codes looks good. Please add a one bank line at few places like Between functions or when you think the code is getting long, just to increase readability.
@@ -0,0 +1,56 @@ | |||
//Code for printing inorder traversal in kotlin | |||
class Node |
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.
Please add one blank line here.
left = right = null; | ||
} | ||
} | ||
class BinaryTree |
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.
Please add one blank line here.
printInorder(root); | ||
} | ||
} | ||
//Main function |
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.
Please add one blank line here.
val arrSize = read.nextLine().toInt() | ||
var arr = IntArray(arrSize) | ||
println("Enter data of binary tree") | ||
for(i in 0 until arrSize) |
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.
Please add one blank line here.
arr[i] = read.nextLine().toInt() | ||
tree.root = new Node(arr[i]); | ||
} | ||
println("Inorder traversal of binary tree is"); |
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.
Please add one blank line here.
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.
Please ensure 4 space indentation in each function. Once you are confident, it is consistent through out, you can squash your commits. I will merge.
fun printInorder(Node: node):void | ||
{ | ||
if (node == null) | ||
return; |
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.
Indentation 4 spaces.
println(node.num); | ||
printInorder(node.right); | ||
} | ||
fun printInorder():void |
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.
Please add one blank line between these functions here also.
|
||
for(i in 0 until arrSize) | ||
{ | ||
arr[i] = read.nextLine().toInt() |
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.
please make this 4 space indentation from start of opening brace. It is 3 currently.
//Main function | ||
fun main() | ||
{ | ||
BinaryTree tree = new BinaryTree(); |
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.
Please make it 4 space indentation in main method.
Updated inorder
Updated inorder
Updated inorder
Fixes #2552
Checklist:
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
Changes proposed in this pull request:
Languages Used:
Files Added:
Thanks!