About Me

My photo
Vijayapur, Karnataka, India
I am interested in Teaching.

Wednesday, 28 June 2023

Laboratory Component: Module 1 (DAA Subject Code:21CS42)

 import java.util.Random;

import java.util.*;

class ss

{

public static void main(String arg[])

{

Scanner sc = new Scanner(System.in);

Random randomGenerator = new Random();

System.out.println("Enter value of n");

int n = sc.nextInt();


int [] a = new int[n] ; 


    for (int i = 0; i < n; i++)

{

         a[i] = randomGenerator.nextInt(100);

       System.out.println("Number :"+a[i]);

    }


long startTime=System.nanoTime();

                int i,j,temp;

// selection sort

                for(i=0;i<=n-2;i++)

                {

                    int min=i;

                    for(j=i+1;j<=n-1;j++)

                    {

                        if (a[j]<a[min])

                            min=j;

                    }

                    temp=a[i];

                    a[i]=a[min];

                    a[min]=temp;

                }


long endTime=System.nanoTime();

long elapseTime=(endTime-startTime);


System.out.println("Sorted Numbers :");

                 for (i = 0; i < n; i++)

{

          System.out.println("Number :"+a[i]);

    }

System.out.println("Time taken to sort array elements is:"+elapseTime+" nano seconds");

System.out.println("Time taken to sort array elements is:"+(float)elapseTime/1000000000+"seconds");

}

}

No comments:

Quiz-1 for DCET 2025 (Introduction to Python)

 1. Introduction to Python https://docs.google.com/forms/d/e/1FAIpQLSc3LFrMaswLg6mltJ3NN5QGbALA9Uc53KWPp4oV5HN4SaM0Iw/viewform?usp=sharing...