Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main5
- {
- public static double[] QuickSort(double[] arr) {
- int elements = arr.length;
- for(int j=0; j<elements; j++)
- {
- int current_position=0; //position of pivot element
- double temp;
- for(int i=1; i<elements; i++) //Partitioning loop
- {
- if(arr[i] <= arr[0])
- {
- current_position++;
- temp = arr[i];
- arr[i] = arr[current_position];
- arr[current_position] = temp;
- }
- }
- temp = arr[0];
- arr[0] = arr[current_position];
- arr[current_position] = temp;
- }
- return arr;
- }
- // MAIN //
- public static void main(String args[]) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Input the number of elements : ");
- int N = sc.nextInt();
- double arr[] = new double[N];
- for (int a = 0; a < N; a++) {
- System.out.printf("Input the [%d] element : ", a);
- arr[a] = sc.nextInt();
- }
- System.out.println();
- double arr1[] = new double[N];
- for (int b = 0; b < N; b++) {
- System.out.printf("Input the [%d] element : ", b);
- arr1[b] = sc.nextInt();
- }
- System.out.println();
- double arr2[] = new double[N];
- for (int c = 0; c < N; c++) {
- arr2[c] = arr[c] / arr1[c];
- }
- System.out.println();
- // Print before sorting...
- System.out.println("Before Sorting : ");
- for(double i:arr2)
- {
- System.out.print(i);
- System.out.print(" ");
- }
- System.out.println();
- QuickSort (arr2);
- // Print after sorting...
- System.out.println("After Sorting : ");
- for(double i:arr2)
- {
- System.out.print(i);
- System.out.print(" ");
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment