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.getR oot() ) ) );
}
Collections.sort(binarylis t);
for(int i=0; i < numtrees ; i++)
{
System.out.println( binarylist.get(i) );
binarylist.remove(i);
}
System.out.println(binaryl ist.size() + " " + binarylist.get(4999) );
}
====================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.getR
}
Collections.sort(binarylis
for(int i=0; i < numtrees ; i++)
{
System.out.println( binarylist.get(i) );
binarylist.remove(i);
}
System.out.println(binaryl
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
I'm glad you did - my answer seems to be strangely truncated ;-)
I'm glad you did - my answer seems to be strangely truncated ;-)
ASKER