Advertisement
GokulDeep

Eqnsorting.java

Apr 27th, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package com.gokul.demo.InProgress;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class EquationSort {
  6.     public static void main(String[] args) {
  7.         int[] nums = {  1, 2, 3 };
  8.         int[] nums2 = { 1,1,1 };
  9.         sortedSquares(nums, nums2);
  10.  
  11.     }
  12.  
  13.     public static int[] sortedSquares(int[] nums, int[] nums2) {
  14.  
  15.         int i = 0;
  16.         for (; i < nums.length ; i++) {
  17.  
  18.             nums[i] = (nums2[0] * nums[i] * nums[i]) + (nums2[1] * nums[i]) + nums2[2];
  19.             System.out.println(nums[i]);
  20.         }
  21.  
  22.         for (int p = 1; p < nums.length; p++) {
  23.             int key = nums[p];
  24.             int j = p - 1;
  25.  
  26.             while (j >= 0 && nums[j] > key) {
  27.                 nums[j + 1] = nums[j];
  28.                 j--;
  29.             }
  30.  
  31.             nums[j + 1] = key;
  32.         }
  33.  
  34.  
  35.         System.out.println(Arrays.toString(nums));
  36.         return nums;
  37.     }
  38.  
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement