uopspop

Untitled

Dec 24th, 2020
749
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.basic;
  2.  
  3. public class Sort_Bubble_new {
  4.     public static void bubble_sort(int[] nums) {
  5.         for (int round = 0; round < nums.length; round++) {
  6.             // int len = nums.length - round; // improved version
  7.             int len = nums.length;
  8.             for (int i_runner = 1; i_runner < len; i_runner++) {
  9.                 if (nums[i_runner - 1] > nums[i_runner]) { // if faster, swap
  10.                     swap(nums, i_runner - 1, i_runner);
  11.                 }
  12.             }
  13.         }
  14.     }
  15.  
  16.     private static void swap(int[] nums, int i_left, Integer i_right) {
  17.         int tmp = nums[i_left];
  18.         nums[i_left] = nums[i_right];
  19.         nums[i_right] = tmp;
  20.     }
  21.  
  22.     public static void main(String[] args) {
  23.         int[] nums = new int[]{8, 2, 6, 10, 4};
  24.         Sort_Bubble_new.bubble_sort(nums);
  25.  
  26.         System.out.println();
  27.     }
  28. }
  29.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×