Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- //class to calculate runtime in millisec
- public class timeCount {
- public static void main(String[] args) {
- //to take input array size
- Scanner s=new Scanner(System.in);
- System.out.println("Input array size");
- int n=s.nextInt();
- //store the total running time
- long running_time=0;
- System.out.println("Number of Items to sort");
- //to take number of random arrays
- int num=s.nextInt();
- //generate num number of random arrays
- for(int i=0;i<num;i++){
- int[] arr=sort.generateRandomArr(n);
- //record the start time
- long start_time=System.currentTimeMillis();
- //sort using bubble sort
- sort.bubble_sort(arr, n);
- //record the end time
- long end_time=System.currentTimeMillis();
- //add the time taken to total running time
- running_time=running_time+(end_time-start_time);
- }
- System.out.println("The number of items sorted:"+num);
- //average running time for each array
- double avg_time=(double)running_time/num;
- System.out.println("Average Running Time:"+avg_time);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement