In C Write a program to output a binary search tree in ascen

In C++

Write a program to output a binary search tree in ascending order.

Solution

#include <iostream>
using namespace std;
void printSorted(int arr[], int start, int end)
{
if(start > end)
    return;

// print left subtree
printSorted(arr, start*2 + 1, end);

// print root
cout<<arr[start];

// print right subtree
printSorted(arr, start*2 + 2, end);
}

int main()
{
int arr[] = {4, 2, 5, 1, 3};
int arr_size = sizeof(arr)/sizeof(int);
printSorted(arr, 0, arr_size-1);
return 0;
}

In C++ Write a program to output a binary search tree in ascending order.Solution#include <iostream> using namespace std; void printSorted(int arr[], int

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site