Example Code

Selection Sort

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This is an example of a selection sort.

 

Description

This VI implements selection sort fully programmed in LabVIEW. In addition, it allows you to set a wait in the main loop and displays the partially sorted array so that you can see the actual process that selection sort takes to sort the array. See the Wikipedia entry for the detailed process on how the sorting is accomplished.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Download and open the Selection Sort VI.
  2. Set values for the Unsorted Array. The example uses horizontal sliders to make the sort visually interesting.
  3. Set the wait value and run the VI.

 

Additional Information or References

 

Caveats and Additional Notes

Selection sort has O(n²) complexity meaning in layman's terms that the larger the size of the array, the time it takes to sort and the number of comparisons it makes increases exponentially. There are many sorting algorithms that are much more efficient and take less memory. This algorithm should only be used to learn the process of different sorting methods or in the rare case that you need to actually sort using selection sort. Otherwise, LabVIEW includes a VI called Sort 1D Array.VI that implements a version of Quicksort that should be used instead.

 

Additional Sorting Examples Programmed in LabVIEW

Bubble Sort

 

Block Diagram of Selection Sort VI
1.png

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.