XetoWare
  • Home
  • Products
    • Multimedia >
      • Air Media Player
      • Ace Video Converter
      • FLV Player
      • Video2MP3
      • ASCII Artist
    • Utilities >
      • Fast Shutdown
      • UltraHide
      • WinLock
      • HotKey Utility
    • File Management >
      • uZip
    • Legacy Software >
      • Any Media Player
      • File Shredder
      • GoogleIt
      • Password Generator
      • Windows Hacker
  • Services
    • AdPush
    • Custom Software
    • VerifyMyApp
  • Blog
  • Contact Us

Recursive Bubble Sort Method in Java

11/10/2014

Comments

 
Recently, there have been some requests on code that sorts an array of unique integers in ascending order using recursion.
    public static int[] recursiveBubbleSort(int[] list, int n) {
        if (n == 1) {
            return list; //finished sorting
        }
        
        int temp;
        for (int i = 0; i < n-1; i++) {
            if (list[i+1] < list[i]) {
                temp = list[i];
                list[i] = list[i+1];
                list[i+1] = temp;
            }
        }
        return recursiveBubbleSort(list, n-1);
    }
To test this method, use the code below.

    public static void main(String[] args) {
        int[] arr = {-1, 10, -999, 20, 1, 2, 3, -100, 200, 20000, 99999, -99999};
        System.out.println(Arrays.toString(recursiveBubbleSort(arr, arr.length)));
    }

    
Note: Imports java.util.Arrays; is needed at the top of the class file.

Happy coding.
Comments

    About

    XetoWare has a blog where we occasionally update with tutorials and solutions to common PC tasks and problems.



    Categories

    All
    Hardware
    Programming
    Reviews
    Security
    Services
    Software
    Tutorials

    RSS Feed



Privacy Policy | Uninstall Instructions | Installer Policy
Copyright (c) XetoWare 2018
  • Home
  • Products
    • Multimedia >
      • Air Media Player
      • Ace Video Converter
      • FLV Player
      • Video2MP3
      • ASCII Artist
    • Utilities >
      • Fast Shutdown
      • UltraHide
      • WinLock
      • HotKey Utility
    • File Management >
      • uZip
    • Legacy Software >
      • Any Media Player
      • File Shredder
      • GoogleIt
      • Password Generator
      • Windows Hacker
  • Services
    • AdPush
    • Custom Software
    • VerifyMyApp
  • Blog
  • Contact Us