-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryTreeSort.java
45 lines (35 loc) · 905 Bytes
/
BinaryTreeSort.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Copyright (C) Deepali Srivastava - All Rights Reserved
This code is part of DSA course available on CourseGalaxy.com
*/
import java.util.Scanner;
public class BinaryTreeSort
{
private BinaryTreeSort(){} //this class is not for instantiation
public static void sort(int[] a, int n)
{
BinarySearchTree tree = new BinarySearchTree();
for(int i=0; i<n; i++)
tree.insert(a[i]);
tree.inorder(a);
}
public static void main(String[] args)
{
int i,n;
int[] a = new int[20];
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number of elements : ");
n = scan.nextInt();
for(i=0; i<n; i++)
{
System.out.print("Enter element " + (i+1) + " : ");
a[i] = scan.nextInt();
}
sort(a,n);
System.out.println("Sorted array is : ");
for(i=0; i<n; i++)
System.out.print(a[i] + " ");
System.out.println();
scan.close();
}
}