I just implemented data structure (i.e. array based positional list) and thought I should test with 100000+ number of elements because my array must grow and shrink as size increase to same as capacity and size decrease to 1/4 of capacity.
size refers to number of elements in array and capacity to initial size of array during its creation.
As you can think if I am looping 100k times it will take time.
But what's happening is it is printing the output before loop and then system take around 10-20 seconds (little more or less,using Intellij Idea Ultimate) to execute that loop and after loop executes, console just get cleared and then the output is printed which is following the loop.
Why is this happening
And Is there any other way,to execute loop faster
Loop
Random generator = new Random();
for (int i = 0; i < 100000; i++) {
if (i % 2 == 0) {
array_positional_list.addLast(generator.nextInt(3));
if (i % 4 == 0)
array_positional_list.addBefore(cursor, generator.nextInt(3));
} else {
array_positional_list.addFirst(generator.nextInt(3));
if (i % 4 == 0)
array_positional_list.addAfter(cursor, generator.nextInt(3));
}
}
Aucun commentaire:
Enregistrer un commentaire