Sorting algorithm essay

The Array class is highly similar with the one which you have learnt in text book (Chapter 2). It now has some more methods. The randomly() method is used to generate an array of random long integer values. Public void randomly(into implements) { // create a random machine Random random = new Random(); unless = implements; for (into I = O; I The static method now in class Timeless is used for this purpose. It returns number of mill-seconds since epoch. You can refer to http:// download. Oracle. Com/Java’s/6/docs/API/ for more information about how to use Calendar class. Public static long now() Calendar cal = Calendar. Assistance(); Date currently = cal. Getting(); return currently. Getting(); f. The code in Sorting is now modified to measure time needed by Bubble sorting method. into maximizes = 1 0000; // array size or new Array(maximizes); // create the array ear. Indolent(maximizes); // generate random array’s elements long starriest, meantime; // get time just before running sorting starriest = Timeless. Now(); // get time just after running sorting meantime = Timeless. Now(); // time needed in mill-seconds duration = meantime – starriest; ” + duration + “ms”); g. Until now, hopefully you can understand the way we measure running time of Bubble sort. Your task now is to write selections() and insertions() method in class Array. If you forget them, you can refer to Chapter 3 in textbook.

Note: because after sorting by bubble sort, the array is changed. Thus you need to create a copy of the original array to apply for each sorting method. Copy constructor Array (Array array) can be used to create a copy of the array. To check algorithms code correct or not, you can use display() method. It prints out content of an array. H. Play around your program with different maximizes values and record their running time into a table as mentioned above.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!

order now