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 Selection Sort Method in Java

11/10/2014

Comments

 
Here is the code to recursively sort an unique array of integers in Java. 
    public static int[] recursiveSelectionSort(int[] list, int n) {
        if (n == list.length - 1) {
            return list;
        }
        int temp, lowestIndex = n;
        for (int i = n + 1; i < list.length; i++) {
            if (list[i] < list[lowestIndex]) {
                lowestIndex = i;
            }
        }
        temp = list[n];
        list[n] = list[lowestIndex];
        list[lowestIndex] = temp;
        return recursiveSelectionSort(list, n+1);
    }
To test this method, use the code below.

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

    
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