Skip to content
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

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

sandhyabhan
Copy link
Contributor

@sandhyabhan sandhyabhan commented Mar 30, 2020

Fixes #2552

Checklist:

  • 4 space indentation.
  • Coding conventions are followed.
  • Input is taken dynamically.
  • Sample Input / Output is added at the end of file.
  • Logic Documentation (Comments).
  • File names are correct.

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:

  • Add Inorder Traversal in Kotlin.

Languages Used:

  • Kotlin

Files Added:

  • Inorder_Traversal.kt

We're happy to help you get this ready -- don't be afraid to ask for help.

Thanks!

Copy link
Collaborator

@singh-shreya6 singh-shreya6 left a 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);
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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.

Tree_Inorder_Traversal/Inorder_Traversal.kt Show resolved Hide resolved
Tree_Inorder_Traversal/Inorder_Traversal.kt Show resolved Hide resolved
Copy link
Collaborator

@singh-shreya6 singh-shreya6 left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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");
Copy link
Collaborator

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.

Copy link
Collaborator

@singh-shreya6 singh-shreya6 left a 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;
Copy link
Collaborator

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
Copy link
Collaborator

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()
Copy link
Collaborator

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();
Copy link
Collaborator

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.

@singh-shreya6 singh-shreya6 merged commit 971acfb into jainaman224:master Apr 9, 2020
afroz23 pushed a commit to afroz23/Algo_Ds_Notes that referenced this pull request Apr 25, 2020
Amitsharma45 pushed a commit to Amitsharma45/Algo_Ds_Notes that referenced this pull request May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree Inorder Traversal
2 participants