Example Code

Bubble 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 that allows you to apply bubble sort on an array.

 

 

Description

This VI implements bubble 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 bubble 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 the attached folder "Array Bubble Sorting_LV2012_NI Verified"

2. Open the project and launch the VI Bubble Sort

3. Adjust the slider values in Unsorted Array to modify the values to be sorted.
4. Set the Wait to View value to see the actual process that bubble sort takes to sort the array in the Partially Sorted Array
5. Run the VI

 

 

Additional Information or References

 

Bubble sort has an average 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 bubble sort. Otherwise, LabVIEW includes a VI called Sort 1D Array.VI that implements a version of Quicksort that should be used instead.

 

You can find additional Sorting Examples Programmed in LabVIEW here Selection Sort

 

Block Diagram & Front Panel

BD.PNG

FP.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.