URI Online Judge Solution 1195 Binary Search Tree – Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1195 Binary Search Tree  | Beginner
URI Problem Link – https://www.urionlinejudge.com.br/judge/en/problems/view/1195

Problem Name: 1195 Binary Search Tree solution
Problem Number : URI – 1195 Binary Search Tree code
Online Judge : URI Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)

URI Online Judge Solution 1195 Binary Search Tree - Solution in C, C++, Java, Python and C#

URI Problem 1195 simple input output

Input Sample Output Sample
2
3
5 2 7
9
8 3 10 14 6 4 13 7 1
Case 1:
Pre.: 5 2 7
In..: 2 5 7
Post: 2 7 5

Case 2:
Pre.: 8 3 1 6 4 7 10 14 13
In..: 1 3 4 6 7 8 10 13 14
Post: 1 4 7 6 3 13 14 10 8

URI Solution 1195 Binary Search Tree  Code in C / URI 1195 code in cpp:

#include <cstdio>
using namespace std;

struct Node
{
int data;
Node* left;
Node* right;
};

Node* GetNewroot(int data)
{
Node* newroot = new Node();
newroot -> data = data;
newroot -> left = NULL;
newroot -> right = NULL;
return newroot;
}

Node* Insert(Node* root, int data)
{
if(root == NULL){ //empty tree
root = GetNewroot(data);
return root;
}else if(data <= root -> data){
root -> left = Insert(root -> left, data);
}else{
root -> right = Insert(root -> right, data);
}

return root;
}

void printPreOrder(struct Node* root)
{
if (root == NULL)
return;
printf(" %i", root -> data);
printPreOrder (root -> left);
printPreOrder (root -> right);
}

void printInOrder(struct Node* root)
{
if (root == NULL)
return;
printInOrder (root -> left);
printf(" %i", root -> data);
printInOrder (root -> right);
}

void printPosOrder(struct Node* root)
{
if (root == NULL)
return;
printPosOrder (root -> left);
printPosOrder (root -> right);
printf(" %i", root -> data);
}

int main()
{
int c, n, x, count = 1;

scanf("%i", &c);

for (int i = 0; i < c; ++i)
{
Node* root = NULL;
scanf("%i", &n);

for (int j = 0; j < n; ++j)
{
scanf("%i", &x);
root = Insert(root, x);
}

printf("Case %i:n", count);
printf("Pre.:");
printPreOrder(root);
printf("n");

printf("In..:");
printInOrder(root);
printf("n");

printf("Post:");
printPosOrder(root);
printf("n");

count++;
//if(i != (c - 1))
printf("n");
}

return 0;
}

URI Solution 1195 Binary Search Tree  Code / URI 1195 solution in CPP:

URI Solution 1195 Binary Search Tree  Code / URI 1195 solution in Java:

URI Solution 1195 Binary Search Tree  Code / URI 1195 solution in  Python:

URI Solution 1195 Binary Search Tree  Code / URI 1195 solution in  C# (C Sharp):

Demonstration:

Just implement this in coding. Since having any problem just put a comment below. Thanks

Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI 1195 Binary Search Tree  code in C, URI 1195 Binary Search Tree  code in C++, URI Area of a circle solution in C, URI solution, URI 1195 Binary Search Tree  solution in C,URI 1195 Binary Search Tree  solution in C++-CPP, URI 1195 Binary Search Tree  solution in C# (C sharp),URI 1195 Binary Search Tree  solution in Java,URI 1195 Binary Search Tree  solution in Python,

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *