0

i m working with this program but dont know how to add counter in it in order to check running / execution time of program.please help me. and telll how and where to add code for this task?plz reply soon.

public class InsertionSort{
    public static void main(String a[]){
        int i;
        int array[] = {12,9,4,99,120,1,3,10};

        System.out.println("       Insertion Sort\n\n");   
        System.out.println("Values Before the sort:\n");    
        for(i = 0; i < array.length; i++)
        System.out.print( array[i]+"  ");
        System.out.println();
        insertion_srt(array, array.length);        
        System.out.print("Values after the sort:\n");    
        for(i = 0; i <array.length; i++)
        System.out.print(array[i]+"  ");
        System.out.println();   
        System.out.println("PAUSE");                 
    }

    public static void insertion_srt(int array[], int n){
        for (int i = 1; i < n; i++){
            int j = i;
            int B = array[i];
            while ((j > 0) && (array[j-1] > B)){
                array[j] = array[j-1];
                j--;
            }
            array[j] = B;
        }
    }
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by darkagn
0

System.currentTimeMillis() will give you the current time in milliseconds. Call this method before your code does anything else, then again after your code is finished, then find the difference and you have the number of milliseconds that your code ran for.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.