Hi guys am creating a Binary Search Tree Program so far it works fine and everything but I am trying to arrange the random numbers generated after the in order transversal in ascending order here is my code

// C
 // This Binary Search Program inputs 25 Random workers and outputs them in different orders.
 using System;
 using BinaryTreeLibrary;

 // class TreeTest declaration
 public class TreeTest
 {
    // test class Tree
    static void Main( string[] args )
    {
       Tree tree = new Tree();
      int insertValue;

      Console.WriteLine( "Inserting values: " );
      Random random = new Random();

       // insert 25 random integers from 0-99 in tree
       for ( int i = 1; i <= 25; i++ )
       {
          insertValue = random.Next( 100 );
          Console.Write( insertValue + " " );

         tree.InsertNode( insertValue );
       } // end for

       // perform inorder traversal of tree
       Console.WriteLine("\n\nInorder traversal");
       tree.InorderTraversal();

         // Sort Random??? 
        


       // perform preorder traversal of tree
       Console.WriteLine( "\n\nPreorder traversal" );
       tree.PreorderTraversal();

       

      // perform postorder traversal of tree
      Console.WriteLine( "\n\nPostorder traversal" );
       tree.PostorderTraversal();

    } // end method Main
 } // end class TreeTest

You can do it like this:

int[] array = new int[25];
Random random = new Random();
// insert 25 random integers from 0-99 in tree
for ( int i = 0; i < 25; i++ )
{
    int value = random.Next(0,101);
    array[i] = value;
}

//sort in ascending order:
Array.Sort(array);   //array is now sorted in asc

//sort in descending order (if you need it):
Array.Reverse(array); //array is now sorted in asc

Hope it helps,
Mitja

This question has already been answered. Start a new discussion instead.