Link to home
Start Free TrialLog in
Avatar of tyweed420
tyweed420

asked on

Simple walk through of an array list is giving me an out off bounds exception .

I have created an arrarylist which holds the height of 10,000 binarysearchtrees I'm simply trying to print the height of every tree out of the arraylist. However at index[50000] it is giving me the error. But i print the size of the arraylist before and it is 10000 i just can't figure this out.Any ideas why this is happening would be great

====================code=========================

import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;

public class RandomGenerator
{

      public static void main(String [] args)
      {
        ArrayList binarylist = new ArrayList();
        ArrayList Avllist = new ArrayList();

          AvlTree a;
          BinarySearchTree b ;
          Random random = new Random();
        int numtrees =   10000;              //Integer.parseInt(args[0]);
        int sizetrees =   100;            //Integer.parseInt(args[1]);

        //create binary trees
          for (int i=0; i < numtrees ;i++)
          {
                  b = new BinarySearchTree();
            a = new AvlTree();

                //create # int's inside tree
                  for(int j=0; j < sizetrees; j++)
                  {
                    b.insert(random.nextInt() );
                    a.insert(random.nextInt() );

                }


          binarylist.add(new Integer(b.height()) );
          Avllist.add(new Integer(a.getHeight(a.getRoot() ) ) );


            }



     Collections.sort(binarylist);

     for(int i=0; i < numtrees ; i++)
     {
             System.out.println( binarylist.get(i) );

             binarylist.remove(i);
       }



System.out.println(binarylist.size() + " " +  binarylist.get(4999) );






}



ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tyweed420
tyweed420

ASKER

yeah i understand you thanks! dummy me:)
:-)

I'm glad you did - my answer seems to be strangely truncated ;-)