John F. Bergin               

Bellevue, WA

(425) 242-1394

 

John.F.Bergin@Comcast.net                            Resume

 

Word Formatted Resume (Right Click and "Save Target As")

 

Cover Letter                                                    White Papers                                            Code Examples

Senior Software Engineer                                                                                                                                                                                                          

Code Examples by John F. Bergin

 

    Sort an Array of Integers - Bubble Sort

    The following program uses a "Bubble" sorting algorithm to sort an array of integers:

 

    // Sort An Array - Bubble Sort
    static bool BubbleSortIntegers(int *inputArray, int size) 
    { 
         // Make sure size is greater than 1  
         if ( size <= 1 ) return 1; 
  
         // Use exception handling 
         try{ 
               int iTemp=0, i=0; 
               while ( i < size - 1 ) 
               { 
                    if ( inputArray[i] > inputArray[i+1] ) 
                    { 
                         // Switch values and start over 
                         iTemp = inputArray[i+1]; 
                         inputArray[i+1] = inputArray[i]; 
                         inputArray[i] = iTemp; 
                         i=0; 
                    } 
                    else 
                    { 
                         i++; 
                    } 
               } 
         } 
         catch(...){return 1;}; 
  
         return 0; 
    }; 

 

    The following Test Window shows the results of a test of the bubble sort program:

   

 

 

____________________________

Copyright © 2010 by John F. Bergin.

Home